How to style the menu items on an Android action bar

前端 未结 8 1427
孤城傲影
孤城傲影 2020-11-28 04:55

There\'s been many questions on styling on action bars, but the ones I\'ve found either are relating to styling the tabs, or have answers that don\'t work for me.

Th

相关标签:
8条回答
  • 2020-11-28 05:18

    I did this way:

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="actionMenuTextAppearance">@style/MenuTextAppearance</item>
        <item name="android:actionMenuTextAppearance">@style/MenuTextAppearance</item>
        <item name="actionMenuTextColor">@color/colorAccent</item>
    </style>
    
    <style name="MenuTextAppearance" >
        <item name="android:textAppearance">@android:style/TextAppearance.Large</item>
        <item name="android:textSize">20sp</item>
        <item name="android:textStyle">bold</item>
    </style>
    
    0 讨论(0)
  • 2020-11-28 05:24

    You have to change

    <style name="MyActionBar.MenuTextStyle"
    parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    

    to

    <style name="MyActionBar.MenuTextStyle"
    parent="android:style/TextAppearance.Holo.Widget.ActionBar.Menu">
    

    as well. This works for me.

    0 讨论(0)
  • 2020-11-28 05:28

    Instead of having the android:actionMenuTextAppearance item under your action bar style, move it under your app theme.

    0 讨论(0)
  • 2020-11-28 05:28

    I think the code below

    <item name="android:actionMenuTextAppearance">@style/MyActionBar.MenuTextStyle</item> 
    

    must be in MyAppTheme section.

    0 讨论(0)
  • 2020-11-28 05:28

    BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);

        TextView textView = (TextView) navigation.findViewById(R.id.navigation_home).findViewById(R.id.smallLabel);
        textView.setTypeface(Typeface.DEFAULT_BOLD);
        textView = (TextView) navigation.findViewById(R.id.navigation_home).findViewById(R.id.largeLabel);
        textView.setTypeface(Typeface.DEFAULT_BOLD);
    
    0 讨论(0)
  • 2020-11-28 05:30

    My guess is that you have to also style the views that are generated from the menu information in your onCreateOptionsMenu(). The styling you applied so far is working, but I doubt that the menu items, when rendered with text use a style that is the same as the title part of the ActionBar.

    You may want to look at Menu.getActionView() to get the view for the menu action and then adjust it accordingly.

    0 讨论(0)
提交回复
热议问题