There is no need to do changes in ANDROIDMAINFEST.xml
checkout this
you can achieve it by this in fragment or in activity by provideing or masking with it custom theme and after making the custom theme you have to pass that context to the popup menu.
first create popup menu layout in menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/remove"
android:title="Remove downloads"
/>
</menu>
second style it in style.xml
<style name="CustomPopUpStyle" parent="Widget.AppCompat.PopupMenu">
<item name="android:textColor">@android:color/white</item>
<item name="android:itemBackground">@color/bgColor</item>
</style>
method
private fun showPopupMenu(context: Context, view: View) {
var wrapper: Context = ContextThemeWrapper(context, R.style.CustomPopUpStyle)
val popup = PopupMenu(wrapper, view)
popup.inflate(R.menu.popup_menu)
popup.setOnMenuItemClickListener(PopupMenu.OnMenuItemClickListener { item: MenuItem? ->
when (item!!.itemId) {
R.id.remove -> {
Toast.makeText(context, item.title, Toast.LENGTH_SHORT).show()
}
}
true
})
popup.show()
}
lastly initialization
showPopupMenu(holder.itemView.context, holder.viewDataBinding.more)
and this i did in adapter of recyclerview which is in fragment
hope you liked it.
the code is self explanatory too.