Android Programming Tutorials

(Romina) #1
Now Your Friends Seem Animated

private View statusRow=null;

...and initialize it somewhere late in onCreate():


statusRow=findViewById(R.id.status_row);

Then, add a status_entry menu option to Patchy/res/menu/option.xml:


<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/prefs"
android:title="Settings"
android:icon="@drawable/ic_menu_preferences"
/>
<item android:id="@+id/status_entry"
android:title="Hide Status Entry"
android:icon="@drawable/status_hide"
/>
<item android:id="@+id/location"
android:title="Insert Location"
android:icon="@drawable/ic_menu_compass"
/>
<item android:id="@+id/help"
android:title="Help"
android:icon="@drawable/ic_menu_help"
/>
</menu>

You will need to supply some PNG image to serve as the menu icon,


preferably 32px tall.


The menu option is initially set up in "hide" mode. However, when the user


pops up the menu, we want to change that menu option to "show" mode if


the StatusEntryView is already hidden. To do this, we can use


onPrepareOptionsMenu() – add the following method to Patchy:


@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem statusItem=menu.findItem(R.id.status_entry);

if (statusRow.getVisibility()==View.VISIBLE) {
statusItem.setIcon(R.drawable.status_hide);
statusItem.setTitle("Hide Status Entry");
}
else {
statusItem.setIcon(R.drawable.status_show);

265
Free download pdf