我有一个奇怪的问题。我创建了一个简单的 Button
看起来像这样:
<com.google.android.material.button.MaterialButton
android:id="@+id/continue_button"
android:background="@drawable/green_button_selector"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/landing_margin"
android:layout_marginEnd="@dimen/landing_margin"
android:layout_marginBottom="@dimen/landing_margin"
android:text="@string/login_button_text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
我想做
Button
绿色带圆角,所以我创建了一个名为 green_button_selector
的 xml 文件并设置为按钮背景。此文件代码发布在下面<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle">
<solid android:color="@color/colorGreenButton" />
<corners android:radius="10dp" />
</shape>
但是我的按钮没有变成绿色,而是我的应用程序的 colorAccent,任何想法我做错了什么?
最佳答案
如果您使用的是 Material 按钮,则无需创建自定义可绘制对象。
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:backgroundTint="@android:color/holo_green_dark"
app:cornerRadius="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="BUTTON" />
更多:https://material.io/develop/android/components/material-button/
关于android - 无法将形状应用于按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53168301/