I am trying to implement an update button in my application so that the user can manually re-synchronize with the web server. The code works, but it's hard for me to understand the representations of actions (at least I think I should use).
My menu item is here:
<item
android:id="@+id/main_menu_refresh"
android:enabled="true"
android:icon="@drawable/refresh"
android:orderInCategory="1"
android:showAsAction="ifRoom"
android:title="@string/refresh"
android:actionViewClass="android.widget.ProgressBar">
</item>
The problem is that it always shows a ProgressBar. I wondered if it works as a search widget (the only example I really see on the Internet), and added a tag collapseActionViewto showAsAction, and this prevented it from appearing immediately. However, when I click the refresh button, the icon disappears (good), but also the Title title on the action bar and ProgressBar appears on the left side of the window where the name used to be. And not what I wanted.
- , actionViewClass XML:
MenuItem refresh = (MenuItem)findViewById(R.id.main_menu_refresh);
Log.w("MyApp", "Have Menu");
ProgressBar pb = new ProgressBar(ReadingList.this);
refresh.setActionView(pb);
, setActionView.
, ( , , ProgressBar ), .
, , . , , , , , . .
: sastraxi.
public class IconSwitcher extends LinearLayout{
public IconSwitcher(Context context) {
super(context);
ProgressBar pb = new ProgressBar(context);
ImageView iv = new ImageView(context);
addView(iv);
addView(pb);
}
}
. , :
MenuItem refresh = (MenuItem)findViewById(R.id.main_menu_refresh);
IconSwitcher ic = (IconSwitcher) refresh.getActionView();
. IconSwitcher. XML :
<item
android:id="@+id/main_menu_refresh"
android:enabled="true"
android:icon="@drawable/refresh"
android:orderInCategory="1"
android:showAsAction="ifRoom"
android:title="@string/refresh"
android:actionViewClass="IconSwitcher">
</item>
IconSwitcher.
2: .
MenuItem refresh = (MenuItem)findViewById(R.id.main_menu_refresh);
refresh.setVisible(false);
, . ?