我有一个ConstraintLayout,我正在我的应用程序中用作弹出窗口,我希望这个弹出窗口是半透明的。
我试过像#333000000这样的颜色,它应该是半透明的黑色,但它看起来像浅灰色。如果我将背景颜色设置为"@android:color/transparent",它会变为白色,所以我认为问题是我有一个默认的白色背景。
此外,当我设置圆角时,我会看到我的ConstrinatLayout后面有圆角的白色背景。
这是我的ConstraintLayout代码。我有几个文本视图和一个图像在里面。
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="350dp"
android:layout_height="475dp"
android:background="#33000000"
android:padding="10dp"
android:layout_gravity="center">
如果需要更多的代码或详细信息,请告诉我。
以下屏幕截图的半径为50dp,背景颜色为#B3808080。
弹出屏幕截图
在style.xml中的基本主题标记下设置WindowdisablePreview
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowDisablePreview">true</item>
</style>
然后在对话框方法中设置背景透明
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));