1

I'm trying to do something like the mockup below. I need the first item to have a different background than the others. I also need this first item to be unclickable. I tried the enabled="false" attribute but that greys out the text which I don't want. Also I have tried itemBackground in styles.xml to change the item background color but this changes all of them and I only want the first item to have a different background. And lastly, I'd like some indentation in the last two items (not sure if this is even possible as I don't see padding and margin attributes).

enter image description here

nicoqueijo
  • 872
  • 2
  • 11
  • 28

1 Answers1

-1

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>
  • How this code will help in achieving any of the OP requirements? – Ahmed Ahmedov May 05 '22 at 08:47
  • in above code is self-explanatory if you are stuck with the same problem you will easily get the solution right now I will not discuss much but the manifest file I mentioned because we have to set the theme of the popup menu and the second thing once that is done you can modify your style according to your requirement – Vishal kumar singhvi May 06 '22 at 09:31
  • I am trying to achieve something very similar to what OP wants and right now I am leaning towards that its not possible at all using the manifest or not, just because Widget.PopupMenu doesn't provide such an option. If you have any suggestion for resolving any of the problems OP meets, please provide them. Thanks! Using PopupWindow like described here: https://stackoverflow.com/a/49706629/466577 does the job. – Ahmed Ahmedov May 07 '22 at 20:07
  • The above question asked if he wants to update the style or change some background color I think- https://stackoverflow.com/questions/12636101/how-to-style-popupmenu. – Vishal kumar singhvi May 09 '22 at 05:30
  • This will change all items colors and background colors. The OP wants to change one item color, another item ident and so on. Doesn't look like PopupMenu provides such a functionality. – Ahmed Ahmedov May 09 '22 at 08:32