代码之家  ›  专栏  ›  技术社区  ›  user4857063

更改XAML中ToolBarItem的颜色

  •  8
  • user4857063  · 技术社区  · 9 年前

    <ContentPage.ToolbarItems>
    
        <ToolbarItem Text="About" 
                     Icon="ic_action_more_vert.png"
                     Priority="0"
                     Order="Secondary"
                     Clicked="ToolbarItem_Clicked"/>
    
        <ToolbarItem Text="Settings"
                     Icon="ic_action_more_vert.png"
                     Priority="0"
                     Order="Secondary"/>
    
    </ContentPage.ToolbarItems>
    

    这就是我想要改变的。带白色文本的黑色菜单,要更改背景颜色和文本颜色。你知道如何做到这一点吗?

    enter image description here

    4 回复  |  直到 9 年前
        1
  •  12
  •   Guillermo Daniel Arias    8 年前

    我找到了一个解决方案: https://forums.xamarin.com/discussion/40529/toolbaritem-textcolor

    简单添加到“styles.xml”:

    <item name="android:actionMenuTextColor"> @color/orange </item>
    

    我花了几个小时找它。。

        2
  •  8
  •   Grace Feng    9 年前

    首先,你可以找到 styles.xml Resources 在Android项目中:

    enter image description here

    <style name="AppToolbarTheme" parent="Theme.AppCompat.NoActionBar">
      <item name="android:colorBackground">#2196F3</item>
      <item name="android:textColor">#000080</item>
    </style>
    

    然后打开 Toolbar.axml 在android项目中

    enter image description here

    app:popupTheme 属于 Toolbar 这样地:

    app:popupTheme="@style/AppToolbarTheme"
    

    更新:

    工具栏 :

    <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="?attr/actionBarSize"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/AppToolbarTheme" />
    
        3
  •  1
  •   Victor Hugo Terceros    6 年前

    这对我有用

    styles.xml

    <item name="android:actionMenuTextColor">#000080</item>

        4
  •  0
  •   octobus Kuldeep Singh    6 年前

    android:theme android:theme="@style/ThemeOverlay.AppCompat.Light" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"