我正在尝试为按钮提供渐变背景和更强的笔触。我已经阅读/看过很多教程,但对我来说没有用。
这是我的插件.xml文件
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:shape="rectangle">
<gradient android:startColor="#25AAFF"
android:endColor="#004F81">
</gradient>
<stroke
android:width="5dp"
android:color="#000000">
</stroke>
<corners android:radius="5dp"></corners>
注意:角落工作正常
和按钮文件
<Button
android:background="@drawable/login_button"
android:id="@+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/login_password_input"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="@string/login_button_text"
android:textColor="#FFFFFF"
android:textStyle="bold">
</Button>
使用材料成分库,<Button />
和<com.google.android.material.button.MaterialButton />
之间没有区别。检查this post了解更多信息。
MaterialButton
忽略 android:background
,直到释放1.2.0-alpha06
。在此版本中,您可以使用类似以下内容的渐变背景:
<Button
android:background="@drawable/bg_button_gradient"
app:backgroundTint="@null"
... />
还可以使用app:cornerRadius
,app:strokeWidth
和app:strokeColor
属性应用笔划:
<Button
app:cornerRadius="4dp"
app:strokeWidth="1dp"
app:strokeColor="@color/primaryLightColor"
..>
如果使用的是材料组件库的早期版本,则可以使用AppCompatButton
:
<androidx.appcompat.widget.AppCompatButton
android:background="@drawable/bg_button_gradient"
..>