Android 透明 属性 不适用于 Android 4.1.1

Android transparent property does not work on Android 4.1.1

我试图使 ButtonseditText 变得透明,我使用的是自定义 xml 文件,它按预期在 Android 5 上工作(所有字段确实是透明的),但是当 运行 在模拟器上使用 Android 4.1.1 的同一个应用程序时,这些字段显示为黑色。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    android:background="@android:color/transparent">
    <stroke android:width="3px" android:color="#FFF" />
</shape>

如何在较旧的 android OS 上实现透明效果?

尝试自己定义透明颜色,以确保它不是框架的东西。

<color name="transparent">#00000000</color>

透明绝对适用于果冻豆,所以我怀疑它可能是模拟器。

将背景设置为透明有效 api 4.0 级以上在您的 xml

中添加以下行
 android:background="@android:color/transparent"

或者尝试这样的事情

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
<solid android:color="@android:color/transparent" />
    <stroke android:width="3px" android:color="#FFF" />
</shape>

为形状标签添加颜色 属性:

<solid android:color="@android:color/transparent" />