Android Studio——手机上无法使用径向渐变

3
我正在尝试在我的应用程序中设置径向线性背景。我目前已经在预览上实现了它,但是当我在三星Galaxy S4上运行我的应用程序时,整个背景都变成了起始颜色。
预览效果如下: enter image description here 三星Galaxy S4的效果如下: enter image description here 这是我的XML文件:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <gradient
        android:type="radial"
        android:startColor="#f3e5f5"
        android:endColor="#9c27b0"
        android:gradientRadius="600"
        android:angle="270"
        android:centerX="50%"
        android:centerY="20%"/>

</shape>

有什么想法是错的吗?
2个回答

0

0
我找到了另一个解决方法 - 在代码中设置渐变背景:
findViewById(R.id.bg).setBackground(ContextCompat.getDrawable(context,R.drawable.bg_gradient));

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接