Styling ToolbarItem & ListView's MenuItem in Xamarin Forms ResourceDictionary or inline

André Clements 1 Reputation point
2021-01-21T08:36:35.123+00:00

In a Xamarin Forms app, I can change the appearance of the navigation bar and its text.

   <Style TargetType="NavigationPage">  
                       <Setter Property="BarBackgroundColor" Value="{StaticResource ypBlueSuperLight}" />  
                       <Setter Property="BarTextColor" Value="{StaticResource ypBlueMild}" />  
                   </Style>  

However, menu items appear in white. How does one control their appearance? - I can't seem to find any documentation or examples on how to do this.
Also, when tapping and holding an item in the listview, how does one modify the appearance of the new menu bar and its items that appear?

59030-toolbaritem.jpg

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,326 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 71,931 Reputation points Microsoft Vendor
    2021-01-21T12:23:59.62+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    menu items appear in white. How does one control their appearance?

    You can open xxx.Android/Resources/Values folder. Add following style.

       <style name="AppTheme.ActionBar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">  
           
           <item name="actionMenuTextColor">#ffff00</item>  
             
         </style>  
    

    Then open xxx.Android/Resources/layout, find Toolbar.xml, change the android:theme="@style/AppTheme.ActionBar"

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

    59145-image.png

    when tapping and holding an item in the listview, how does one modify the appearance of the new menu bar and its items that appear?

    Please open the style.xml again. add following attribute to your <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar"> style

       <item name="actionModeBackground">@color/colorAccent</item>  
       <item name="actionMenuTextColor">@color/colorGreen</item>  
    

    59182-image.png

    Best Regards,

    Leon Lu


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.