LoginSignup
2
1

More than 5 years have passed since last update.

Android PopupMenuの背景を設定する方法

Posted at

styles.xml

  • styles.xmlPopupMenuを設定
    • rippleにも対応したいときは colorBackground に任意のcolorを設定します
    • ripple対応しなくていいときは itemBackground でOK
styles.xml
<style name="PopupMenu" parent="@android:style/Widget.PopupMenu">
        <item name="android:colorBackground">@color/my_background_color</item>
</style>

Activity

  • ContextThemeWrapper の第1引数にcontext、第2引数にスタイル R.style.PopupMenu を指定
  • PopupMenu の第1引数に ContextThemeWrapper を指定
HogeActivity.kt
val color = ContextThemeWrapper(this, R.style.PopupMenu)
val popup = PopupMenu(color, view)

これでPopupMenuの背景が設定できます

参考URL

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1