如何显示在使用工具栏底部的行动项目 [英] How to show action items at the bottom using Toolbar
本文介绍了如何显示在使用工具栏底部的行动项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<item
android:id="@+id/action_back"
android:orderInCategory="100"
app:showAsAction="always"
android:icon="@drawable/ic_action_back"
android:title="@string/back"/>
<item
android:id="@+id/action_save"
android:orderInCategory="100"
app:showAsAction="always"
android:icon="@drawable/ic_action_save"
android:title="@string/save"/>
<item
android:id="@+id/action_sort"
android:orderInCategory="100"
app:showAsAction="always"
android:icon="@drawable/ic_action_sort_dark"
android:title="@string/sort"/>
<item
android:id="@+id/action_new"
android:orderInCategory="100"
app:showAsAction="always"
android:icon="@drawable/ic_new"
android:title="@string/new_menu"/>
<activity
android:name="com.app.FileFragmentActivity"
android:uiOptions="splitActionBarWhenNarrow"
android:label="@string/app_name" >
</activity>
输出:
Output:
我想在喜欢的两张截图上面(标记为红色)底部显示操作项目。
我使用工具栏
使用 appcompat-V7
库。
I want to show action items at the bottom like in the two screenshots above (marked in red).
I am using Toolbar
using appcompat-v7
library.
推荐答案
诚如这个帖子(点击) 安卓uiOptions =splitActionBarWhenNarrow
已经在删除的棒棒堂的。虽然这不是什么大不了的事,因为你可以简单地用两个工具栏
- 一个在顶部,一个在底部。
As stated in this post (click) android:uiOptions="splitActionBarWhenNarrow"
has been removed in Lollipop. Though this is not that big of a deal since you can simply use two Toolbars
- one at the top and one at the bottom.
遵循一些基本的例子,code:
Following some basic example code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_top"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_bottom"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="?attr/colorPrimary"
android:layout_alignParentBottom="true"
android:minHeight="?attr/actionBarSize" />
<LinearLayout
android:layout_below="@id/toolbar_top"
android:layout_above="@id/toolbar_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
code
private void initToolbars() {
Toolbar toolbarTop = (Toolbar) findViewById(R.id.toolbar_top);
setSupportActionBar(toolbarTop);
Toolbar toolbarBottom = (Toolbar) findViewById(R.id.toolbar_bottom);
toolbarBottom.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()){
case R.id.action_settings:
// TODO
break;
// TODO: Other cases
}
return true;
}
});
// Inflate a menu to be displayed in the toolbar
toolbarBottom.inflateMenu(R.menu.menu_main);
}
结果
Result
注意:的 搬运时要显示两个工具栏或只有一个是你必须做的手工的
这篇关于如何显示在使用工具栏底部的行动项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文