8

I've added a toolbaritem in my app, however i dont see a way to change its background and text color.

<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>

This is what I'd like changed. The black menu with white text, want to change that bg color and text color. Any idea how to achieve this?

enter image description here

4 Answers4

12

I found a solution :https://forums.xamarin.com/discussion/40529/toolbaritem-textcolor

Simple add to "styles.xml":

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

I've spent hours looking for it..

  • Your approach totally works, however, I have a menu, page title and next. so the color being change is only the secondary which is next, page title still white.any idea? – Pxaml Aug 28 '18 at 19:40
8

As @Gerald Versluis suggested, you can do this by Android styling.

Firstly you can find the styles.xml file under the values folder of Resources in Android project:

enter image description here

Inside of this file, you can open this file and create a style for your menu like this:

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

Then open the Toolbar.axml in android project

enter image description here

and change the app:popupTheme of Toolbar like this:

app:popupTheme="@style/AppToolbarTheme"

Update:

Here is the code of Toolbar:

<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" />
Grace Feng
  • 16,564
  • 2
  • 22
  • 45
  • @Curiousity, are you using XF for development? What is the version? – Grace Feng Jul 27 '17 at 05:18
  • Yes I'm using XF. Version - 4.5 – Curiosity Jul 27 '17 at 05:26
  • @Curiousity, version 4.5? By my side the latest version is 2.3.4.247, try to clean and rebuild your project, if problem still exists, show me your styles.xml. – Grace Feng Jul 27 '17 at 05:30
  • Very sorry. My mistake. The version is 2.3.4.247. Same as yours. And I tried cleaning and rebuilding the project several times. May be I'm missing something. But I did as above. – Curiosity Jul 27 '17 at 05:37
  • @Curiousity, can you please show me all code of your styles.xml and toolbar.axml? Or try to create a new project and this code again. – Grace Feng Jul 27 '17 at 06:03
  • Hi @GraceFeng-MSFT , how do i change the code in Toolbar.axml? currently it shows a blank phone screen with no code :/ –  Jul 27 '17 at 06:48
  • @Unicorn_Girl, you can right click on it and open with "XML (Text) Editor", if you double click on this file, then in the down-left side of screen, click the `Source` button. – Grace Feng Jul 27 '17 at 06:52
  • @GraceFeng-MSFT, Im getting this error - the "http://schemas.android.com/apk/res/android:popupTheme" attribute is not declared. In my toolbar.axml , I have this: android:popupTheme="@style/AppToolBarTheme" /> and in styles.xml I have this: –  Jul 27 '17 at 07:01
  • 1
    @Unicorn_Girl, change `android:popupTheme` to `app:popupTheme`, actually by default there is the theme defined for this property, just change the style to the one we defined (AppToolBarTheme) in styles.xml. – Grace Feng Jul 27 '17 at 07:03
  • @Unicorn_Girl, whatever, I edited my answer and post the whole code of `Toolbar`, you may check it. – Grace Feng Jul 27 '17 at 07:05
  • @GraceFeng-MSFT, It is working now :D . Thanks so much –  Jul 27 '17 at 07:09
  • this saved my life. <3 How on earth can you discover such method like this? @GraceFeng because all the resources in XF are unlike Android Studio which can easily be discover from IntelliSense. – elliotching Jun 07 '18 at 12:05
  • We are in 2021 now, and nothing helps. Android 11 SDK, Xamarin Forms 5.0.0.2196, and menu is still white on black. – Vova l Oct 21 '21 at 15:01
1

This worked for me

In styles.xml

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

Victor Hugo Terceros
  • 2,969
  • 3
  • 18
  • 31
0

To change first item text edit android:theme android:theme="@style/ThemeOverlay.AppCompat.Light" or android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" for second item text edit popupTheme

octobus
  • 1,246
  • 1
  • 14
  • 20
Etnic
  • 76
  • 1
  • 6