0

I want to change the color of the ToolbarItem and the overflow button (3 vertical dots). As I have found out the colorPrimaryDark is responsible for both. If I change the color also the color of the dots or ToolbarItem text color changes. But changing colorPrimaryDark leads to modifications in my generall app for all sorts of elements.

How do I change the color specifically for the items in the ActionBar?

Here I define AppTheme for my app in MainActivity.cs:

[Activity(Theme = "@style/AppTheme", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
    // ...    
}

In themes_apptheme.xml under Resources/values I have defined my AppTheme:

<?xml version="1.0" encoding="utf-8"?>

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="AppTheme" parent="android:Theme.Material.Light">
        <!-- ... -->
        <item name="android:colorPrimaryDark">@color/primaryDark</item>
        <item name="android:textColorPrimary">@color/primaryDark</item>
        <item name="android:actionBarStyle">@style/MyActionBarTheme</item>
    </style>

</resources>

In styles.xml under Resources/values there is the referenced MyActionBarTheme:

<?xml version="1.0" encoding="utf-8"?>

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="MyActionBarTheme" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:homeAsUpIndicator">@drawable/ic_back</item>
        <!--<item name="android:background">@color/primaryDark</item>-->
        <item name="android:textColorPrimary">@color/white</item>
        <item name="android:actionMenuTextColor">@color/white</item>
        <item name="android:actionModeBackground">@color/primaryDark</item>
    </style>

</resources>

I've tried the solutions from the similar questions (e.g. textColorSecondary), but non of them worked or specifically targets my needs. For the dots an image could be used, but that doesn't change the color of ToolbarItem and seems not to be necessary. Also other solutions are using the newer Toolbar instead of the ActionBar. Furthermore the themes are different. Can I somehow use a custom renderer? Or would it be sufficient to add one item to my style? Which one is it?

PS: I'm using Xamarin.Forms 2.5.0.121934

Edit:

My goal is to have a white color for the overflow button and the ToolbarItem text. This can be achived, if I use the following:

<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
    <!-- ... -->
</style>

The downside of this approach is, that the background of ContextAction is black and I don't know how to change the color (as before with the dots and the toolbar button). Styling in Android is a big hassle for me.

R15
  • 13,982
  • 14
  • 97
  • 173
testing
  • 19,681
  • 50
  • 236
  • 417
  • I think overflow button is a image icon which you need to choose what color you want. – R15 Nov 08 '18 at 12:37
  • @CGPA6.4: When I change the `textColorPrimary` the "*image*" color changes too. Don't know how this happens. For me it seems like it would be a `TextView`. – testing Nov 08 '18 at 12:47
  • Visit this might be useful https://stackoverflow.com/questions/35932669/how-do-i-change-the-action-bar-overflow-button-color – R15 Nov 08 '18 at 12:51
  • @CGPA6.4: Tried the first two solutions without success. I added them to the file, where `AppTheme` is defined. The used theme in most answers is different from mine. – testing Nov 08 '18 at 13:04
  • In your android project resource folder you have Toolbar axml file. Apply newly created Style on that. in xaml file itself. – R15 Nov 08 '18 at 13:09
  • That is the thing. I use `ActionBar`, not `Toolbar`. Therefore I have no *Toolbar.xml* file. Perhaps I have to switch to `Toolbar`. FYI: I edited my question. – testing Nov 08 '18 at 13:11

0 Answers0