自定义 Button 选择器

640?wx_fmt=gif

640?wx_fmt=gif

640?wx_fmt=other

极力推荐文章:欢迎收藏Android 干货分享 

640?wx_fmt=other

本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以下内容:

1.自定义Button 背景选择器

Android中自带的Button样式比较丑,为了美化Button 可使用一下方法。

640?wx_fmt=jpeg

自定义 Button 实现效果

1.自定义Button 背景选择器

自定义Button 背景选择器 custom_btn_selector.xml

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- 按下去的背景颜色显示效果 -->
    <item android:drawable="@drawable/btn_pressed" android:state_pressed="true"/>
    <!-- 获取焦点时背景颜色显示效果 -->
    <item android:drawable="@drawable/btn_pressed" android:state_focused="true"/>
    <!-- 没有任何状态下的背景颜色 -->
    <item android:drawable="@drawable/btn_normal"/>

</selector>

2.自定义Buton 素材

640?wx_fmt=other

btn_pressed.9.png

640?wx_fmt=other

btn_normal.9.png

3.自定义Button 背景


    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:textColor="@android:color/white"
        android:textSize="18sp"
        android:background="@drawable/custom_btn_green_selector"
        android:text="自定义Button选择器" />

640?wx_fmt=jpeg

640?wx_fmt=jpeg

长按识别二维码,领福利

至此,本篇已结束,如有不对的地方,欢迎您的建议与指正。同时期待您的关注,感谢您的阅读,谢谢!

如有侵权,请联系小编,小编对此深感抱歉,届时小编会删除文章,立即停止侵权行为,请您多多包涵。

640?wx_fmt=gif

640?wx_fmt=png

posted @ 2019-04-17 12:10  程序员Android的博客  阅读(85)  评论(0)    收藏  举报