【发布时间】:2021-11-13 13:39:47
【问题描述】:
这是我在 StackOverflow 上的第一个问题,我希望得到社区的大力帮助 :) 我已经四处寻找这个问题的解决方案几个小时,但我有点困惑..
我正在尝试为我的 android 应用程序创建一个自定义的轮廓圆形按钮,但是当我通过 XML 文件中的 android:background 属性应用它时,它并不能正常工作。默认背景颜色(紫色)不会被移除。也没有应用中风。但是,边角是圆角的。
有人说 android:background 不适用于 MaterialButtons。有人说在 theme.xml 文件中创建一个样式并通过 android:backgroundTint 属性重新应用它(它也不起作用)。 有人说尝试以编程方式更改它(也不起作用!)。
请提供有效的解决方案。
这是我的代码以及我用它实现的目标。
activity_main
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:background="@drawable/round_button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
round_button
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@color/black" />
<stroke
android:width="3dp"
android:color="@color/teal_200" />
<corners android:radius="25dp" />
</shape>
我真的很期待您的回答!谢谢。
【问题讨论】:
标签: android android-button android-background