自定义 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 @   程序员Android的博客  阅读(80)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
点击右上角即可分享
微信分享提示