【问题标题】:How to create custom button with xml style如何使用 xml 样式创建自定义按钮
【发布时间】:2013-10-08 12:32:57
【问题描述】:

请建议某人如何在 android 中使用 xml 样式创建这样的按钮,而无需仅借助颜色、形状和样式来使用任何图像。

【问题讨论】:

    标签: android


    【解决方案1】:

    为此使用layer-list。试试下面的代码

    <Button
            android:id="@+id/button_register"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/button_background"
            android:text="Cancel"
            android:padding="15dp"
            android:textStyle="bold"
             />
    

    button_background.xml

        <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    
        <item>
            <shape android:shape="rectangle" >
    
        <gradient
            android:endColor="#FFFFFF"
            android:startColor="#A9A9A9"
            android:type="linear" />
    
    
                <stroke
                    android:width="2dp"
                    android:color="#5E2612" />
    
    
                <corners
                    android:bottomLeftRadius="10dp"
                    android:bottomRightRadius="10dp"
                    android:topLeftRadius="10dp"
                    android:topRightRadius="10dp" />
            </shape>
        </item>
        <item
            android:bottom="4dp"
            android:left="4dp"
            android:right="4dp"
            android:top="4dp">
            <shape android:shape="rectangle" >
                <gradient
                    android:angle="90"
                    android:endColor="#A9A9A9"
                    android:startColor="#FFFFFF"
                    android:type="linear" />
    
                <corners
                    android:bottomLeftRadius="10dp"
                    android:bottomRightRadius="10dp"
                    android:topLeftRadius="10dp"
                    android:topRightRadius="10dp" />
    
    
            </shape>
        </item>
    
    </layer-list>
    

    它应该可以工作

    【讨论】:

    • 它现在可以工作了,请建议我如何像提到的图像那样做
    • 这个风格和你想要的图片几乎一样。让我知道你还想要什么?
    【解决方案2】:

    查看这些示例如何创建自定义按钮。 Link1 Link2

    【讨论】:

      猜你喜欢
      • 2013-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多