您的位置:首页 > 移动开发 > Android开发

Android自定义按钮样式

2012-09-27 22:19 375 查看
使得按钮在不同的状态有不同的背景图片是本篇的主要类容

在res/drawable下新建一个buttonstyle.xml文件,这个文件用于描述按钮的样式

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_pressed="true" android:drawable="@drawable/btn_p"/>
    <item android:state_pressed="false" android:drawable="@drawable/btn_n"/>
</selector>


还有很多的样式如下图



在布局文件中添加一个Button,使用buttonstyle.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/buttonstyle"
        />

</LinearLayout>

这样就完成了Button的样式。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: