【问题标题】:Andriod Studio Button color not changingAndroid Studio 按钮颜色不变
【发布时间】:2021-07-02 06:22:41
【问题描述】:

在我的 android 应用程序中,我希望按钮的角之一是圆角的,并且它的颜色不同于默认值。我创建了一个 xml 文件来实现这一点。将此 xml 文件设置为按钮的背景后,形状已更改,但颜色保持默认。我尝试将此 xml 文件设置为 TextView 的背景,并且效果很好。 button_shape.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="20dp" />
    <solid android:color="#03A9F4" />
</shape>

按钮:

<Button
    android:id="@+id/btRandom"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="250dp"
    android:background="@drawable/button_shape"
    android:text="MyButton"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/tvTitle" />

【问题讨论】:

  • 您好,您可以尝试将按钮的色调更改为#03A9F4
  • 我已经尝试过了,但是如果背景设置为那个 xml 文件,即使我改变了色调,颜色也不会改变。
  • 您可以尝试使用该背景和色调创建按钮样式并将其应用于此按钮

标签: xml android-studio button


【解决方案1】:

将文件夹 res--> values--> Themes-> Themes.xml 下的 Theme.MaterialComponents.DayNight.DarkActionBar 替换为 Theme.AppCompat.DayNight.DarkActionBar。在 android studio 4.1 中,默认情况下,一个主题已经应用在 Buttons 上。然后你可以简单地说:例如android:background="@color/black"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    • 2021-04-17
    • 2015-12-01
    • 2015-11-10
    • 2021-10-04
    • 1970-01-01
    相关资源
    最近更新 更多