【发布时间】: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