将多个操作项添加到Android中的多个工具栏

时间:2015-08-04 00:29:58

标签: android xml user-interface toolbar

到目前为止,我已经实现了以下目标:

Multiple Toolbars Implementation Demonstration

我正在使用 Appcompat Library 来自定义我的工具栏。

正在使用的文件: 一个。 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是可绘制文件夹下的图像文件。

我的问题:

一个。如何将菜单项添加到特定工具栏,即不同的操作项到顶部和底部工具栏?是否可以通过xml声明实现,而无需使用toolbar.setLogo()等等?

湾有没有办法将 menu_main.xml 中声明的每个项目分配给一个特定的工具栏?例如。上面屏幕截图中的卢比图像仅作为操作项放在底部工具栏中?

请原谅我这个问题的愚蠢是模糊的。它引起了我的好奇心。

谢谢。

1 个答案:

答案 0 :(得分:0)

在每个工具栏中,您应声明其ActionMenuView

  #kiosk_btn{font-size: 3vh; background-color: #141E26; border:none; box-shadow: 5px 5px 5px black; margin: 2vh; padding-top:2vh; color:white;}
  #kiosk_btn:active{outline: none; text-decoration: none;}
  #kiosk_btn:focus{outline: none; text-decoration: none; }
  #kiosk_btn:hover{text-decoration: none; background-color: #213140;}
  h2{text-align: center;}