How to change background color popup menu android

后端 未结 12 2418
北恋
北恋 2020-11-29 03:47

I generate each option of menu from querying database. Here is my code.

final PopupMenu popupMenu = new PopupMenu(getBaseContext(), v); 
SQLiteDatabase db =          


        
相关标签:
12条回答
  • 2020-11-29 03:51

    In the layout where you are giving toolbar, specify theme by app:popupTheme="@style/MyPopupMenu"

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:minHeight="?attr/actionBarSize"
        android:background="#2196F3"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        style="@style/DrawerArrowStyle"
        app:popupTheme="@style/MyPopupMenu">
    
    </android.support.v7.widget.Toolbar>
    
    0 讨论(0)
  • 2020-11-29 03:52
    <style name="AppTheme1" parent= "android:Theme.DeviceDefault">
    
        <item name="android:actionBarPopupTheme">@style/popupNew</item>
    </style>
    
    <style name="popupNew" parent="android:ThemeOverlay.Material.Light">
        <item name="android:colorBackground">#ffffff</item>
    </style>
    
    0 讨论(0)
  • 2020-11-29 03:54

    Add popupMenu style to ur AppTheme:

    <style name="AppTheme" parent="android:Theme.Light">
        <item name="android:popupMenuStyle">@style/PopupMenu</item>
    </style>
    
    <style name="PopupMenu" parent="@android:style/Widget.PopupMenu">
        <item name="android:popupBackground">@android:color/white</item>
    </style>
    

    manifest.xml:

     <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
    .............
    </application>
    
    0 讨论(0)
  • 2020-11-29 03:55

    You can use custom layout like this..

    PopupMenu pop = new PopupMenu(MainActivity.this, v);
    pop.getMenuInflater().inflate(R.menu.main, pop.getMenu());
    pop.show();
    

    Design layout how you want..hope this helps..

    0 讨论(0)
  • 2020-11-29 03:56

    Please Refer How to style PopupMenu? for more explanation. I was facing the same issue, searched alot but found the solution in the link mentioned.

    PopupMenu is created in following way :

    PopupMenu popup = new PopupMenu(context, view);
    

    PopupMenu takes the styling of the context which is passed, Passing Activity as the context solved my problem.

    0 讨论(0)
  • 2020-11-29 03:58

    Please Add Following lines in style xml file, I hope this will help for material design application. Style.xml

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
    
        <!-- To change the popup menu and app text color  -->
        <item name="android:textColor">@color/colorPrimary</item>
    
        <!-- To change the background of options menu-->
        <item name="android:itemBackground">@color/skyBlue</item>
    </style>
    

    For more details refer this link http://www.viralandroid.com/2016/01/how-to-change-background-and-text-color-of-android-actionbar-option-menu.html

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