我创建了一个像这样的PopupWindow:
PopupWindow popupWindow = new PopupWindow(LayoutInflater.from(this).inflate(R.layout.main_popup_navigation, null, false), ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setWidth((int) this.getResources().getDimension(R.dimen.navigation_popup_width));
popupWindow.showAsDropDown(toolbar);
它工作正常,但它没有任何背景。弹出窗口的背景是完全透明的。
如何设置类似于PopupMenu的背景(窗口+阴影)或ThemeOverlay.AppCompat.Light主题的Spinner?谢谢。
答案 0 :(得分:0)
微调器类型背景
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#CABBBBBB"/>
<corners android:radius="2dp" />
</shape>
</item>
<item
android:left="0dp"
android:right="0dp"
android:top="0dp"
android:bottom="2dp">
<shape android:shape="rectangle">
<solid android:color="@android:color/white"/>
<corners android:radius="2dp" />
</shape>
</item>
</layer-list>
设置背景
popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(this, R.drawable.spinner_background));
答案 1 :(得分:0)
<强> MainActivity.java 强>
popupWindow.setBackgroundDrawable(this.getDrawable(R.drawable.main_bg_navigation));
popupWindow.setElevation(43);
<强> main_bg_navigation.xml 强>
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/white"/>
<corners android:radius="2dp"/>
</shape>
它成功了。 :)
修改:白色值为&#34; fffafafa&#34;