【问题标题】:Gradient color background in button [duplicate]按钮中的渐变颜色背景[重复]
【发布时间】:2021-08-14 07:25:01
【问题描述】:

我创建了一个 XML 文件,用于为我的按钮提供圆形和渐变颜色。

在布局文件中,尽管使用了 android:background="@drawable/button_color,但还是出现了白色按钮。

我需要用我的渐变色替换它。

有人可以查看我的代码吗?

提前致谢。

这是我的代码:

这是我的 XML:res>drawable>button_color.xml

<shape
    android:shape = "rectangle"
    xmlns:android = "http://schemas.android.com/apk/res/android" >

    <corners android:radius="25dp" />
    <gradient android:angle="270"
        android:endColor="#36aec6"
        android:startColor="#8cc542" />

</shape>

布局文件:

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

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="100dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="8dp">

            <ImageView
                android:id="@+id/logoImage"
                android:layout_width="50dp"
                android:layout_height="match_parent"
                android:layout_alignParentStart="true"
                android:layout_marginStart="0dp"
                android:src="@drawable/logo"
                android:contentDescription="@string/acuvisor" />

            <ImageView
                android:id="@+id/companyName"
                android:layout_width="170dp"
                android:layout_height="match_parent"
                android:layout_toEndOf="@id/logoImage"
                android:src="@drawable/company_name"
                android:contentDescription="@string/acuvisor" />

            <TextView
                android:id="@+id/Help"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/help"
                android:layout_alignParentEnd="true"
                android:layout_centerInParent="true"
                android:textSize="16sp"
                android:clickable="true"
                android:padding="12dp"
                tools:ignore="RelativeOverlap" />


        </RelativeLayout>
    </com.google.android.material.appbar.AppBarLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/languageRV"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="8dp"
        android:layout_margin="12dp"/>

    <Button
        android:id="@+id/nextButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:text="@string/next"
        android:textColor="@color/black"
        android:background="@drawable/button_color"/>

</LinearLayout>

输出:

屏幕

【问题讨论】:

  • 检查此answer 包含您需要的内容

标签: android android-layout android-button


【解决方案1】:

使用 AppCompat 主题,而不是像这样的 Material 主题

Theme.AppCompat.DayNight.DarkActionBar

但是,如果您仍想使用材质按钮,只需在设置渐变背景的行前添加 app:backgroundTint="@null" 属性即可。

【讨论】:

    猜你喜欢
    • 2019-07-14
    • 2021-04-22
    • 2012-06-16
    • 1970-01-01
    • 1970-01-01
    • 2022-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多