android - 在titlecase工具栏android中添加菜单项文本和文本

标签 android xml android-layout xamarin

我使用这段代码,我想添加 action1 和 action2,比如这段文字的图片和颜色变化

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    />

菜单

  <?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
        <item android:id="@+id/ok" android:text="action1" app:showAsAction="never" />
        <item android:id="@+id/cancel" android:text="action2"  app:showAsAction="ifRoom" />
    </menu>

我的风格

 <style name="MyTheme" parent="MyTheme.Base">   
  </style>
  <!-- Base theme applied no matter what API -->
  <style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
    <item name="windowNoTitle">true</item>
    <!--We will be using the toolbar so no need to show ActionBar-->
    <item name="windowActionBar">false</item>
    <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette-->
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">#2196F3</item>
    <!-- colorPrimaryDark is used for the status bar -->
    <item name="colorPrimaryDark">#1976D2</item>
    <!-- colorAccent is used as the default value for colorControlActivated
         which is used to tint widgets -->
    <item name="colorAccent">#FF4081</item>   
     <!-- You can also set colorControlNormal, colorControlActivated
         colorControlHighlight and colorSwitchThumbNormal. --> 
  </style> 

我的工具栏

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    android:background="@color/theme_color"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

enter image description here

最佳答案

使用下面的菜单文件-

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
    <item android:id="@+id/ok" app:showAsAction="always"
        android:title="Action1" />
    <item android:id="@+id/cancel" app:showAsAction="always"
        android:title="Action2" />
</menu>

你需要设置android:title="action2"

关于android - 在titlecase工具栏android中添加菜单项文本和文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35432784/

相关文章:

android - 为什么使用 Android ADB shell 的 SQLite 3 命令返回 "permission denied"?

java - 有没有自动格式化XML的Swing组件?

android - 运行 Android 2.x 时布局中的全尺寸水平进度条

java - Android:无法从原始查询填充 ListView

android - AutoTextView 最大尺寸问题

Android 将 Maps v2 API 添加到主详细信息流 - 错误膨胀类 fragment

java - Android 谷歌地图 v2 可点击标记标题

java - 在 xml 文件中使用 CDATA 来解析 html 数据

android - Android 应用程序中的高内存使用率 (50MB)

xml - 如何将文本从一个 XML 文件复制到另一个