【发布时间】:2015-10-26 05:51:15
【问题描述】:
到目前为止,我已经实现了以下目标:
我正在使用 Appcompat 库 来自定义我的工具栏。
正在使用的文件: 一种。 app_bar.xml(顶部工具栏) 湾。 app_bar_bottom.xml(底部工具栏)
我的 main_menu.xml 看起来像这样:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="@+id/notices"
android:orderInCategory="100"
android:title="@string/notices"
android:icon="@drawable/ic_notices_white_24dp"
app:showAsAction="never" />
<item
android:id="@+id/exchange_rate"
android:orderInCategory="100"
android:title="@string/exchange_rate"
app:showAsAction="always"
android:icon="@drawable/ic_rupees_white_24dp"/>
在 app_bar_bottom.xml 我在 MainActivity.java 中做了类似的事情:
toolbar = (Toolbar) findViewById(R.id.app_bar_bottom);
toolbar.setLogo(R.drawable.ic_rupees_white_24dp);
setSupportActionBar(toolbar);
ic_rupees_white_24dp是drawable文件夹下的一个图片文件。
我的问题:
一个。如何将菜单项添加到特定工具栏,即顶部和底部工具栏的不同操作项?是否可以只通过xml声明而不必使用toolbar.setLogo()等来实现?
b.有没有办法将 menu_main.xml 中声明的每个项目分配为仅设置为一个特定的工具栏?例如。上面截图中的卢比图片只作为操作项放在底部工具栏上?
请原谅我的愚蠢问题含糊不清。它只是出于我的好奇心而引起的。
谢谢。
【问题讨论】:
标签: android xml user-interface toolbar