【发布时间】:2021-02-20 12:58:42
【问题描述】:
API 22. 我想为我的按钮设置一个边框半径,所以我这样做了:How to make the corners of a button round? (我尝试了正确的答案)。 How to change the color of a button? 这里的任何方法都不起作用。 我曾经使用 android:backgroundTint 设置按钮的背景颜色。那是唯一有效的方法。不幸的是,当我通过 android:background="@drawable/roundbutton" 将文件链接到我的按钮时,我通过 android:backgroundTint 选择的颜色不起作用。以及我在可绘制/圆形按钮中定义的纯色。奇怪的是,边界半径有效: 我在 activity_main.xml 中的代码:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/signinotherbutton"
android:background="@drawable/roundbutton"
android:backgroundTint="@color/grey"
android:textColor="@color/white"
android:textAllCaps="false"/>
我的 drawable/roundbutton.xml 代码:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" >
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<solid android:color="@color/grey"/>
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<solid android:color="@color/grey"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<solid android:color="@color/grey"/>
</shape>
</item>
</selector>
结果:具有我定义的半径的按钮,但具有默认颜色(约紫色) 不,@color/grey 绝对是灰色,而不是紫色。 谢谢大家的回答
【问题讨论】:
-
您在应用中使用的是哪个主题?
标签: android button colors radius