android - 无法使我的 ConstraintLayout 半透明/透明
问题描述
我有一个 ConstraintLayout,我在我的应用程序中用作弹出窗口,我希望这个弹出窗口是半透明的。
我尝试过使用#33000000 之类的颜色,它应该是半透明的黑色,但它显示为浅灰色。如果我将背景颜色设置为“@android:color/transparent”并且它变为白色,那么我认为问题是我喜欢默认的白色背景。
此外,当我设置圆角时,我看到我的 ConstrinatLayout 后面的白色背景带有圆角。
这是我的 ConstraintLayout 代码。我有几个 TextViews 和一个图像里面。
<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。
解决方案
在 Base 主题标签下的 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));
推荐阅读
- githooks - Git-Hook post_commit 不打印 GIT_DIR 环境来记录
- python - 四阶非线性微分方程的稳定解
- python - 了解 Dask-ML
- python-3.x - 我想删除种子并使用输入插入特定的十六进制键
- javascript - PRISMA:如何在 prisma 常规类型中跳过 id 字段?
- powershell - powershell - 使用管道过滤后显示最后一个事件
- mongodb - 具有预排序和限制的mongodb聚合
- xamarin - Xamarin 下载文件到 - 路径访问被拒绝
- scripting - 无法从用 Tcl 编写的应用程序中找到包
- c++ - 迭代在 cicle C++ 期间改变大小的无序集