小样
需求
我想把自定义按钮与选择器.
上面给出了模拟.
谢谢.
解决方法:
基本上你需要创建一些新的XML文件并将它们应用到你的Button元素.正如我从模型中看到的那样,你需要一个笔划和应用了一些阴影效果的背景颜色,你可以更多地研究阴影,但背景颜色和笔触非常直接.
这是一个例子,done_rounded_btn.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:state_enabled="true"
android:drawable="@drawable/zzzzzzzzz_btn_orange" />
<item
android:state_focused="true"
android:state_enabled="true"
android:drawable="@drawable/zzzzzzzzz_btn_orange" />
<item
android:state_focused="false"
android:state_enabled="false"
android:drawable="@drawable/zzzzzzzzz_btn_inactiv" />
<item android:drawable="@drawable/zzzzzzzzz_btn_black"/>
</selector>
对于选择部分,然后创建与模型对应的自定义drawable.
一个例子,zzzzzzzzzz_btn_orange:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid
android:color="@color/done_color">
</solid>
<corners
android:bottomLefTradius="3dp"
android:bottomrighTradius="3dp"
android:topLefTradius="3dp"
android:topRighTradius="3dp" />
</shape>
<Button
android:id="@+id/registers_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:background="@drawable/done_rounded_btn"
android:text="@string/done_txt"
android:textColor="@color/white"
android:textSize="15sp" />
希望这可以帮助!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。