【问题标题】:Android gradient drawable not showing on button [duplicate]Android渐变可绘制未显示在按钮上[重复]
【发布时间】:2021-03-26 21:33:51
【问题描述】:

我对 StackOverFlow 比较陌生 - 所以如果您对此问题有疑问,请在 cmets 中告诉我。

我正在创建一个基本的 Android 应用程序,其材质按钮的背景设置为渐变可绘制对象,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:angle="0"
        android:endColor="#027FEE"
        android:startColor="#2CC6F2" />
</shape>

主活动:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
 >

    <com.google.android.material.button.MaterialButton
        android:layout_width="wrap_content"
        android:backgroundTint="@drawable/mygrad"
        android:text="Gradient Test"
        android:layout_height="wrap_content"/>
</LinearLayout>

问题是 - 这曾经可以工作,但我在 2 天后返回项目并且看不到渐变:

enter image description here

虽然渐变确实显示在迷你预览中,但在其他任何地方都看不到:

enter image description here

我不知道为什么会遇到这个问题,因为我是按照书本上的。

干杯, 汤姆

【问题讨论】:

    标签: android android-layout kotlin android-xml android-drawable


    【解决方案1】:

    请更换

    android:backgroundTint="@drawable/mygrad"
    

    android:background="@drawable/mygrad"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-21
      • 1970-01-01
      相关资源
      最近更新 更多