美文网首页
自定义控件显示样式(通过设置style)

自定义控件显示样式(通过设置style)

作者: Beck766 | 来源:发表于2018-04-04 09:23 被阅读0次
<Button
    android:id="@+id/btn_changIcon"
    android:layout_width="300dp"
    android:layout_height="60dp"
    android:text="拍照上传新头像"
    style="@style/ButtonCenter"
    android:layout_centerHorizontal="true"
/>

style.xml:

<style name="ButtonCenter">
    <item name="android:gravity">center</item>
    <item name="android:textSize">26sp</item>
    <item name="android:textColor">#FFFFFF</item>
    <item name="android:background">@drawable/bg_btn_center</item>
</style>

bg_btn_center.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape>
            <solid android:color="#F74051" />
            <corners android:radius="30dp" />
        </shape>
    </item>

    <item android:state_focused="true">
        <shape>
            <solid android:color="#F74051" />
            <corners android:radius="30dp" />
        </shape>
    </item>

    <item>
        <shape>
            <solid android:color="#F74051" />
            <corners android:radius="30dp" />
        </shape>
    </item>
</selector>

相关文章

网友评论

      本文标题:自定义控件显示样式(通过设置style)

      本文链接:https://www.haomeiwen.com/subject/yvohhftx.html