【发布时间】:2022-01-31 17:56:35
【问题描述】:
我不明白我正在设置一个带有 che 颜色为蓝色的可绘制按钮,但我看到按钮为红色(这是我的主要颜色),但我不知道如何在不修改 的情况下更改颜色colorPrimary 属性。
这是我的按钮:
<Button
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_margin="8dp"
android:background="@drawable/ic_baseline_change_circle_24"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"></Button>
这就是我的可攻击资源:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="@color/blue">
<path
android:fillColor="@android:color/white"
android:pathData="M12,2C6.48,2 2,6.48 2,12c0,5.52 4.48,10 10,10s10,-4.48 10,-10C22,6.48 17.52,2 12,2zM12.06,19v-2.01c-0.02,0 -0.04,0 -0.06,0c-1.28,0 -2.56,-0.49 -3.54,-1.46c-1.71,-1.71 -1.92,-4.35 -0.64,-6.29l1.1,1.1c-0.71,1.33 -0.53,3.01 0.59,4.13c0.7,0.7 1.62,1.03 2.54,1.01v-2.14l2.83,2.83L12.06,19zM16.17,14.76l-1.1,-1.1c0.71,-1.33 0.53,-3.01 -0.59,-4.13C13.79,8.84 12.9,8.5 12,8.5c-0.02,0 -0.04,0 -0.06,0v2.15L9.11,7.83L11.94,5v2.02c1.3,-0.02 2.61,0.45 3.6,1.45C17.24,10.17 17.45,12.82 16.17,14.76z"/>
</vector>
【问题讨论】:
-
如果你想自己处理背景,那么你可以指定
<android.widget.Button>或<androidx.appcompat.widget.AppCompatButton>标签。这将阻止图书馆的充气工厂用MaterialButtons 代替普通的<Button>标签。 -
谢谢,这行得通,但我不明白,如果我按 ctrl 点击
<Button>我已经看到 android.widget.Button 类 -
是的,这有点令人困惑。您在布局编辑器中看到的内容正是您的 IDE 只能从该 XML 告诉您的内容。知道这个布局最终会在运行时用专门的
LayoutInflater.Factory替换MaterialButton代替<Button>是不够聪明的。 (对于 IMO 来说,让 Material Components 默默地做到这一点是一个糟糕的决定。)
标签: java android button drawable