[Android Studio-渐变背景和笔触

问题描述 投票:1回答:1

我正在尝试为按钮提供渐变背景和更强的笔触。我已经阅读/看过很多教程,但对我来说没有用。

这是我的插件.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>

java android android-button material-components-android material-components
1个回答
0
投票

使用材料成分库,<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:cornerRadiusapp:strokeWidthapp:strokeColor属性应用笔划:

<Button
    app:cornerRadius="4dp"
    app:strokeWidth="1dp"
    app:strokeColor="@color/primaryLightColor"
    ..>

如果使用的是材料组件库的早期版本,则可以使用AppCompatButton

<androidx.appcompat.widget.AppCompatButton
    android:background="@drawable/bg_button_gradient"
    ..>
© www.soinside.com 2019 - 2024. All rights reserved.