使得按钮在不同的状态有不同的背景图片是本篇的主要类容

在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的样式。

更多相关文章

  1. Android存储字符串数据到txt文件
  2. [置顶] cocos2d-x 2.x版本之win32 window移植android 环境搭配
  3. android 按钮
  4. android v4/v7兼容包的源码引用
  5. 基于 Android(安卓)NDK 的学习之旅-----JNI LOG 打印
  6. android自定义标题栏progressBar
  7. Android(安卓)私有文件夹 文件的写入与读取
  8. Android之FileProvider :通过FileProvider来获取content uri
  9. Android(安卓)自定义Dialog的实现

随机推荐

  1. 我的Android进阶之旅------>Android之Ani
  2. Android总结 - System UI Mode
  3. Android(安卓)SDK Manager 和 ADT 更新
  4. Android周学习Step By Step(8)--Intent之启
  5. android 水下气泡上升界面效果
  6. Android(安卓)获取当前连接的wifi名称和r
  7. Android(安卓)APP 内部捐赠实现(支付宝&
  8. React Native安卓实现更新下载、安装
  9. AndroidStudio导入旧版本工程若干问题
  10. java化改造--xml布局文件转成java——学