首页 > 解决方案 > 按钮在预览时透明,但在模拟器上稳定

问题描述

我正在尝试将一些按钮设置为透明,部分透明。他们使用透明/纯色渐变。

它们在预览中显示得很好,但在模拟器和我的手机上它失去了所有透明度。

预习

模拟器

这是我的 XML 代码:

<Button
                    android:id="@+id/barbarian"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/button_gradient"
                    android:text="@string/barbarian" />

如果需要,可以使用 xml 渐变代码:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
    android:startColor="@android:color/transparent"
    android:endColor="#FF000000"
    android:angle="0" />
   </shape>

我感谢任何和所有的帮助!

标签: javaandroidxml

解决方案


推荐阅读