言いたいことはそれだけか

KotlinとかAndroidとかが好きです。調べたことをメモします。٩( 'ω' )و

LollipopでActionBarのPopup windowの背景色が変更できない

前回の続きです。

LollipopでActionBarの色が変更できない - Let's go and programming!



ActionBarの背景色は変更できました。次はOverflowボタンを押したときに出てくる
Popup windowの背景色を変更してみます。

popupMenuStyleやpopupBackground、actionDropDownStyleなどを
Themeで指定してみたけれど、全く効果なし。

Lから変わってしまった?ならばLのFrameworkのコードを見てみましょう。
Popup windowの背景画像を指定しているのはここでしょうか。

Cross Reference: /frameworks/base/core/res/res/drawable/popup_background_material.xml

     17 <shape xmlns:android="http://schemas.android.com/apk/res/android"
     18        android:shape="rectangle">
     19 
     20     <corners
     21             android:radius="2dp" />
     22     <solid
     23             android:color="?attr/colorBackground" />
     24 
     25 </shape>

colorBackgroundを色に指定しています。
ちなみに、このAttributeを変更してしまうとApplication全体の背景色が変わってしまいます。
気持ち悪い...笑

f:id:muumuumuumuu:20150128082940p:plain

では背景画像にpopup_background_material.xmlをセットしていることろをoverrideすることはできるのでしょうか?背景画像を指定しているstyleはこれ。

    555     <style name="Widget.Material.AutoCompleteTextView" parent="Widget.AutoCompleteTextView">
    556         <item name="dropDownSelector">?attr/listChoiceBackgroundIndicator</item>
    557         <item name="popupBackground">@drawable/popup_background_material</item>
    558         <item name="popupElevation">@dimen/floating_window_z</item>
    559     </style>


ではこのstyleを使用しているところを見てみましょう。

     36     public AppCompatPopupWindow(Context context, AttributeSet attrs, int defStyleAttr) {
     37         super(context, attrs, defStyleAttr);
     38 
     39         TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs,
     40                 R.styleable.PopupWindow, defStyleAttr, 0);
     41         mOverlapAnchor = a.getBoolean(R.styleable.PopupWindow_overlapAnchor, false);
     42         // We re-set this for tinting purposes
     43         setBackgroundDrawable(a.getDrawable(R.styleable.PopupWindow_android_popupBackground));
     44         a.recycle();
     45     }


上で指定したpopupBackgroundを、コード上から直接指定しています。
ここのRはsupport libraryのリソースです。
ということは各アプリから変更できないのでは...
(support libraryではない本体側もcom.android.internal.Rから同attributeを参照しています。)

誰かできた人いるのかな?