问题描述
我想做与 Honeycomb 平板电脑上的 GMail 应用程序相同的事情.当您单击 Refresh 按钮时,图标将替换为 ProgressBar.我该怎么做?
I would like to do the same thing than the GMail application on Honeycomb tablets. When you click on the Refresh button, the icon is replaced by a ProgressBar. How can I do this?
谢谢
推荐答案
好的,我尝试了 Cailean 的建议,但对我没有用.每次我想将不确定的进度恢复为原始按钮时,它变得不可点击,我使用这个布局来进行进度
Ok, I tried what Cailean suggested but it didn't work for me. Every time I want to revert indeterminate progress to the original button it becomes unclickable, I used this layout for the progress
(actionbar_refresh_progress.xml)
(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)
(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 我找到了另一种更简单的方法.
After browsing the source of the Google IO app, especially this file: http://code.google.com/p/iosched/source/browse/android/src/com/google/android/apps/iosched/ui/HomeActivity.java i found another easier way.
现在我只需要第一个有进度的布局,工作方法如下:
Now I need only the first layout with progress and the working method looks like this:
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"/>
我希望有人觉得这很有用.
I hope someone finds this useful.
这篇关于ActionBar 中的 ProgressBar,例如带有 Refresh 的 GMail 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!