Styling the popup menu in Android 5.0

I’m making my app ready for Android 5.0, I’m using the latest compatibility library, here is what my style looks like.

<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/theme_accent</item>
        <item name="colorAccent">@color/theme_accent_secondary</item>
    </style>

    <style name="AppThemeDark" parent="Theme.AppCompat">
        <item name="colorPrimary">@color/theme_accent</item>
        <item name="colorAccent">@color/theme_accent_secondary</item>
    </style>
</resources>

(The ActionBar color is being set programmatically.)

  • Draw circle in android
  • How do I invoke the search dialog using onSearchRequested()
  • animation to transition between views with rotation on z-axis with depth perception
  • Nexus 6 and MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
  • connecting android apps to mysql database
  • Throwing OutOfMemoryError “pthread_create (1040KB stack) failed: Try again” when doing asynchronous posts using Volley
  • Now, I want the overflow/popup menu to have the dark background like it had in the holo implementation, but I can’t get it to work, here is what it looks like: enter image description here

    I have tried setting the popupMenuStyle but it didn’t work.

    How can I make the popup menu darker?

    Related posts:

    How does one implement drag and drop for Android marker?
    How to stop video playing in VideoView programmatically in android?
    Samsung Multiwindow crash
    TextView Ellipsize (&hellip;) not working
    run service even if the application is closed (killed)
    Playing youtube video in Android app
  • Google Developer Console project creation limit
  • APK won't install: DalvikVM cannot optimize it (Byte swap and verify fails)
  • Is there Android Intent concept in iPhone SDK
  • Android: Speech Recognition without using google server
  • Using ImageView for panoramic view
  • Anko toast() method causes java.lang.NoSuchMethodError when called from Fragment
  • 4 Solutions collect form web for “Styling the popup menu in Android 5.0”

    Stop using the ActionBar. If you want a ToolBar to be set up like an ActionBar, follow this guide on the android-developers blog.

    It actually mentions your use case at Dark Action Bar and provides this code:

    <android.support.v7.widget.Toolbar
        android:layout_height=”wrap_content”
        android:layout_width=”match_parent”
        android:minHeight=”@dimen/triple_height_toolbar”
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    

    Not a full answer but what I found so far:

    In past versions you needed to specify a drawable (Check https://github.com/StylingAndroid/StylingActionBar code and tutorials)

    Apparently, now that is a color. To modify it you need to do specify the following theme:

    <resources xmlns:android="http://schemas.android.com/apk/res/android">
    
        <style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
            <item name="android:actionBarPopupTheme">@style/popupNew</item>
        </style>
    
        <style name="popupNew" parent="android:ThemeOverlay.Material.Light">
            <item name="android:colorBackground">@color/red</item>
        </style>
    
    </resources>
    

    This works correctly if the theme applied to the app is just this.
    If I add android:actionBarPopupTheme to my existing theme, it doesn’t work. I am trying to figure out why.

    Add the property popupTheme to your toolbar:

    <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:background="@color/color_primary"
      app:theme="@style/Theme.AppCompat.Light"
      app:popupTheme="@style/Theme.AppCompat" />
    

    Or define a new style for your toolbar:

    <style name="MyToolBarStyle" parent="Widget.AppCompat.Toolbar">
        <item name="android:background">@color/green</item>
        <item name="popupTheme">@style/Theme.AppCompat.Light</item>
        <item name="theme">@style/Theme.AppCompat</item>
    </style>
    

    Solved my problem by using this style:

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/theme_accent</item>
        <item name="colorAccent">@color/theme_accent_secondary</item>
        <item name="actionBarStyle">@style/AbStyle</item>
        <item name="actionModeBackground">@color/actionmode_bg</item>
    </style>
    
    <style name="AbStyle" parent="Widget.AppCompat.Toolbar">
        <item name="elevation">2dp</item>
        <item name="displayOptions">homeAsUp|showTitle</item>
        <!--showHome-->
    </style>
    
    <style name="AppThemeDark" parent="Theme.AppCompat">
        <item name="colorAccent">@color/theme_accent_secondary</item>
        <item name="actionBarStyle">@style/AbStyle</item>
    </style>
    

    I had to use Widget.AppCompat.Toolbar as the parent actionBarStyle

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.