我正在尝试更改 Android 默认按钮的样式。我在 res 文件夹中的可绘制文件夹中创建了一个名为 custom_button.xml
的 xml 文件,并在 xml 布局文件中引用了它,但是当我运行应用程序时,按钮样式没有更改,而是我失去了原来按钮的轮廓。
custom_button.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
<solid
android:color="#FF0000" />
</shape>
main.xml
<TextView
android:id="@+id/textView1"
android:layout_width="85dp"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textColor="#6600ff"
android:text="" />
<Button
android:id="@+id/button_getDraw"
style="?android:attr/buttonStyleSmall"
android:background="@drawable/custom_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_getDraw"
android:onClick="getLotteryDrawFromWebsite" />
<Button
android:id="@+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_check"
android:onClick="checkNumbers"
android:enabled="false" />
有什么问题吗?提前谢谢..
最佳答案
将您的 custom_button xml 更改为此 .
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FF0000"/>
关于android - 在android中的xml布局中创建自定义按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18784686/