locked
Tint MenuItem Icon RRS feed

  • Question

  • User399655 posted

    I would like to tint the Delete Icon, but don't really know how to do it, try to change style color but can only change the navigation icon's color, the delete icon still black like in the picture.

    this code only work for navigation icon

    <item name="android:textColorSecondary">#FF4081</item>

    well, I think something wrong, but don't know how to do it. I'm still very very new for xamarin :tired_face: can someone please give me some advice?

    Thursday, February 25, 2021 4:18 PM

Answers

  • User371688 posted

    In android , you can add the following style in file styles.xml

    ``` #FF0000

    <style name="MyAwesomeApp.DarkTheme.Base" parent="Theme.AppCompat">
        <!-- Your app's theme defined here -->
    </style>
    <style name="MyAwesomeApp.DarkTheme.Toolbar" parent="MyAwesomeApp.DarkTheme.Base">
        <item name="android:drawableTint">@color/myCustomYellowColor</item>
    </style>
    

    ```

    And apply this style in layout toolbar.axml:

    <?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="?attr/colorPrimary" android:theme="@style/MyAwesomeApp.DarkTheme.Toolbar" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    I tested in the sample code Xamarin.Android - Support v7 Toolbar, the result is:

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, March 5, 2021 9:05 AM

All replies

  • User371688 posted

    Do you mean the Xamarin.Forms MenuItem in xamarin forms or Toolbar in xamarin android ?

    Could you please post more code snippets or a basic demo to github or onedriver so that we can help you better?


    Xamarin forums are migrating to a new home on Microsoft Q&A! We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A! For more information, please refer to this sticky post.

    Friday, February 26, 2021 8:53 AM
  • User399655 posted

    both Xamarin.Forms MenuItem in xamarin forms or Toolbar in xamarin android ? I'm just started to learn.

    I just used the simple Method to change Icon color and It works, but somehow I still want to know how to do other in other way, next time will post more code snippets.

    Friday, February 26, 2021 12:15 PM
  • User377758 posted

    Any updates?

    Tuesday, March 2, 2021 9:54 AM
  • User399655 posted

    I sill don't know how to set up this in xamarin, I just color my icon to the color that I want and use in project. It's not what I want. Trying to learn about Themes. Now lerning something else but will probably post the whole code in github too.

    Tuesday, March 2, 2021 10:08 AM
  • User371688 posted

    In android , you can add the following style in file styles.xml

    ``` #FF0000

    <style name="MyAwesomeApp.DarkTheme.Base" parent="Theme.AppCompat">
        <!-- Your app's theme defined here -->
    </style>
    <style name="MyAwesomeApp.DarkTheme.Toolbar" parent="MyAwesomeApp.DarkTheme.Base">
        <item name="android:drawableTint">@color/myCustomYellowColor</item>
    </style>
    

    ```

    And apply this style in layout toolbar.axml:

    <?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="?attr/colorPrimary" android:theme="@style/MyAwesomeApp.DarkTheme.Toolbar" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    I tested in the sample code Xamarin.Android - Support v7 Toolbar, the result is:

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, March 5, 2021 9:05 AM
  • User399655 posted

    That works! , I have tried, with this android:drawableTint too but doesnt work, maybe something missing or I type something wrong for sure I dont have MyAwesomeApp.DarkTheme.*Toolbar *. Thank you so much. <3

    Friday, March 5, 2021 9:16 PM