进度在动作条,如Gmail应用程序与刷新 [英] ProgressBar in an ActionBar, like GMail app with Refresh
问题描述
我希望做同样的事情比蜂窝片的Gmail应用程序。 当您单击刷新按钮,图标被换成了进度。 我怎样才能做到这一点?
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"/>
而这一次恢复到按钮
and this one to revert to the button
(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"/>
我的code是:
my code was:
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应用程序,特别是该文件的来源后:<一href="http://$c$c.google.com/p/iosched/source/browse/android/src/com/google/android/apps/iosched/ui/HomeActivity.java">http://$c$c.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);
}
菜单项的定义:
Menu item definition:
<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.
这篇关于进度在动作条,如Gmail应用程序与刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!