0
在ActionBarActivity扩展的活动中,我使用supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
和setSupportProgressBarIndeterminateVisibility(true);
将小进度对话框显示为操作栏项目菜单。我如何增加图标和应用边界之间的空间?
我怎样才能更多地分离屏幕?
谢谢!
在ActionBarActivity扩展的活动中,我使用supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
和setSupportProgressBarIndeterminateVisibility(true);
将小进度对话框显示为操作栏项目菜单。我如何增加图标和应用边界之间的空间?
我怎样才能更多地分离屏幕?
谢谢!
不知道你是如何实现了微小的进度条,但......据我知道你需要创建一个customview这一点,对不对?这样的事情:创建一个新的类象RefreshMenuItemHelper:
public class RefreshMenuItemHelper {
private WeakReference<MenuItem> item;
/**
* Set the menu item.
* @param item
*/
public void setMenuItem(MenuItem item) {
this.item = new WeakReference<MenuItem>(item);
}
/**
* Show the indeterminate progress.
*/
public void showLoading() {
if(item != null) {
item.get().setActionView(R.layout.menu_item_action_refresh);
item.get().expandActionView();
}
}
/**
* Stop and dismiss the indeterminate progress.
*/
public void stopLoading() {
item.get().collapseActionView();
item.get().setActionView(null);
}
}
的menu_item_action_refresh仅仅是一个简单的布局是这样的:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="56dp"
android:layout_height="wrap_content"
android:minWidth="56dp">
<ProgressBar
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center"/>
</FrameLayout>
在你
最后:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_refresh:
refreshHelper.setMenuItem(item);
default:
return super.onOptionsItemSelected(item);
}
}
现在,您可以使用showLoading()和stopLoading()来启动或停止不确定的进度。还要确保menu.xml在R.id.action_refresh中有ic_refresh.png。
希望它有帮助!
谢谢@ nicolas-jafelle!我会尝试这个解决方案并评论结果。微小的进度对话框是一个android提供的支持RequestRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS)的菜单;和setSupportProgressBarIndeterminateVisibility(true); http://developer.android.com/reference/android/support/v7/app/ActionBarActivity.html#setSupportProgressBarIndeterminateVisibility(boolean) – benoffi7
认为我试过没有好看的结果... = D –
请添加一些代码相关的refreshHelper变量。我想使用空指针。谢谢!我创建了类并设置了菜单项,但是使用showLoading()并不取决于用户在oncreate()中单击菜单 – benoffi7