我想做与 Honeycomb 平板电脑上的 GMail 应用程序相同的事情。 当您单击 Refresh 按钮时,图标将替换为 ProgressBar。 我该怎么做?
谢谢
最佳答案
好的,我尝试了 Cailean 的建议,但对我没有用。每次我想将不确定的进度恢复为原始按钮时,它变得不可点击,我使用这个布局来进行进度
(actionbar_refresh_progress.xml)
<?xml version="1.0" encoding="utf-8"?>
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center"/>
这个要恢复到按钮
(actionbar_refresh_button.xml)
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/ic_menu_refresh_holo_light"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
我的代码是:
private void setRefreshing(boolean refreshing) {
this.refreshing = refreshing;
if(refreshMenuItem == null) return;
View refreshView;
LayoutInflater inflater = (LayoutInflater)getActionBar().getThemedContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(refreshing)
refreshView = inflater.inflate(R.layout.actionbar_refresh_progress, null);
else
refreshView = inflater.inflate(R.layout.actionbar_refresh_button, null);
refreshMenuItem.setActionView(refreshView);
}
浏览了谷歌IO应用的源码,尤其是这个文件:http://code.google.com/p/iosched/source/browse/android/src/com/google/android/apps/iosched/ui/HomeActivity.java我找到了另一种更简单的方法。
现在我只需要第一个有进度的布局,工作方法如下:
private void setRefreshing(boolean refreshing) {
this.refreshing = refreshing;
if(refreshMenuItem == null) return;
if(refreshing)
refreshMenuItem.setActionView(R.layout.actionbar_refresh_progress);
else
refreshMenuItem.setActionView(null);
}
菜单项定义:
<item android:id="@+id/mail_refresh"
android:title="Refresh"
android:icon="@drawable/ic_menu_refresh_holo_light"
android:showAsAction="always"/>
我希望有人觉得这很有用。
关于android - ActionBar 中的 ProgressBar,例如带有 Refresh 的 GMail 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8198253/