Gmail平板电脑(如Actionbar项) [英] Gmail tablet like Actionbar items
问题描述
我正在尝试使用拆分actionbar/toolbar
来构建应用,例如在Gmail应用中.
I'm trying to build an app with a split actionbar/toolbar
like in the Gmail app.
此行为是否存在任何视图元素,还是我必须自己编写这样的工具栏?
Is there any view element for this behaviour or do I have to write such a toolbar myself?
打开slidingDrawer
时,搜索图标随母版fragment
一起移动.
The search icon is moving with the master fragment
when opening the slidingDrawer
.
推荐答案
要实现此目的,您可以添加新的这篇文章很好实施独立工具栏的概述.为了后代的缘故,我在下面提供了示例代码.
To accomplish this you can add one of the new Toolbar widgets to each of your fragments layouts. The new Toolbar class was designed to be much more flexible than a traditional Actionbar and will work well in this split design. This post is a good overview for implementing a standalone Toolbar. For posterity's sake I've included the sample code for it below.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.blah);
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
// Set an OnMenuItemClickListener to handle menu item clicks
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
// Handle the menu item
return true;
}
});
// Inflate a menu to be displayed in the toolbar
toolbar.inflateMenu(R.menu.your_toolbar_menu);
}
这篇关于Gmail平板电脑(如Actionbar项)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!