动作栏中的数字,如Gmail

Tim*_*len 14 android android-actionbar

我正在尝试在操作栏的右上角显示数据计数.

如果我不使用拆分操作栏,我只会在栏中创建一个TextView,但是当你拆分时,目前无法在顶部操作栏中放置项目.

澄清一下,我的意思是:

Gmail未读计数

Google是否使用了不同的Action Bar实现,还是有办法实现这一目标?我想我记得读过它,但我找不到它的名字.

rof*_*son 25

使用自定义视图和顶部AB的微调器和文本视图,并android:uiOptions="splitActionBarWhenNarrow"在活动的清单声明中启用

//set the actionbar to use the custom view (can also be done with a style)
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

//set the custom view to use
getActionBar().setCustomView(R.layout.custom_ab);
Run Code Online (Sandbox Code Playgroud)

custom_ab.xml使用ImageView,Spinner和TextView进行计数的布局在哪里.

  • 此外,如果你想保持应用程序图标+上限可用性:`getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_CUSTOM); (8认同)
  • ActionBar的自定义视图是对条形图本身的补充,这在文档中并不完全清楚.因此,这个答案基本上就是你所需要的,虽然你忘了提到那时你会调用getActionBar().getCustomView()来在需要时检索视图. (2认同)