android - 在android中的xml布局中创建自定义按钮

标签 android button customization android-xml

我正在尝试更改 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/

相关文章:

android - 无法删除接近警报

继承自两个父主题的 Android XML 主题?

HTML 表单按钮 CSS

ios - 代号 One button with icon - 根据图标大小设置大小

Android 小部件 onClick 不工作

android - 是否可以在android的新导航组件中发送字符串或整数以外的参数

javascript - 如何根据变量值禁用按钮?

php - 自定义 wordpress 主题

javascript - 如何检索自定义 DOM 属性的值?

php - 覆盖多个模块中的 magento block (以及如何忽略其他模块)