Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓:我的PopupWindow';它的背景是透明的_Android_Background_Popupwindow - Fatal编程技术网

Android 安卓:我的PopupWindow';它的背景是透明的

Android 安卓:我的PopupWindow';它的背景是透明的,android,background,popupwindow,Android,Background,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.getR

我创建了一个弹出窗口,如下所示:

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);
它工作正常,只是没有任何背景。弹出窗口的背景是完全透明的


如何设置类似于弹出菜单或主题meoverlay.AppCompat.Light的微调器的背景(窗口+阴影)?谢谢。

微调器类型背景

<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>

MainActivity.java

popupWindow.setBackgroundDrawable(this.getDrawable(R.drawable.main_bg_navigation));
popupWindow.setElevation(43);
main\u bg\u 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>

它成功了


编辑:白色值为“fffafafa”

谢谢,只缺少阴影。:)但是我不能使用ThemeOverlay.AppCompat.Light主题吗?(没有自己创建)更改了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>