anpin / ContextMenuContainer

Native context menu for any Xamarin.Forms or MAUI view
MIT License
55 stars 5 forks source link

Android: change background Color of the ContextMenuContainer #5

Closed Shaboo closed 3 years ago

Shaboo commented 3 years ago

Is it possible to change the background Color of ContextMenuContainer? (in android for now)

if you can give me a hint so I can implement it myself and I can then send a PR, I have tried a lot but no luck (since I have 0 experience in Android Native)

thanks in advance

anpin commented 3 years ago

hi @Shaboo , what do you mean by background number and what are you trying to achieve?

Shaboo commented 3 years ago

holy, I meant Background Color

basically I want the background Color of the Whole menu to be changed, now it is always kinda white

anpin commented 3 years ago

I think one way to achieve that is to change your app theme as described here https://stackoverflow.com/questions/21231404/how-to-change-background-color-popup-menu-android

mhrastegari commented 3 years ago

Couldn't be cross platform option? like a background color property? it would be really useful, specially when you dealing with Dark & Light mode stuff.

anpin commented 3 years ago

nope, since other platforms doesn't provide such functionality. Also provided solution should be sufficient to support light and dark modes on Android.

Shaboo commented 3 years ago

@anpin thanks for the suggestion, I did the following

in Styles.xml

<style name="pop" parent="Widget.AppCompat.PopupMenu">
    <item name="android:textColor">@android:color/white</item>
    <item name="android:itemBackground">#606060</item>
</style>

and inside MainTheme I added

 <style name="MainTheme" parent="MainTheme.Base">
     ......
    <item name="android:popupMenuStyle">@style/pop</item>
  </style>

then in ContextMenuContainerRenderer.ConstructNativeMenu

Context wrapper = new ContextThemeWrapper(Context, Resource.Style.pop);
contextMenu = new PopupMenu(wrapper, child);

then it worked, thanks again

anpin commented 3 years ago

Amazing, I guess we could add theme selection on Android if doesn’t just work via setting theme. Feel free to create PR thanks.

Pavel

On 11 Jul 2021, at 12:38 PM, Mohammad Shaban @.***> wrote:

 Closed #5.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.