res/drawable/btn_selected.xml

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <!-- 获得焦点但未按下时的背景图片 -->    <item android:drawable="@drawable/ic_launcher" android:state_enabled="true" android:state_focused="true" android:state_pressed="false"/>    <!-- 按下时的背景图片 -->    <item android:drawable="@drawable/a" android:state_enabled="true" android:state_pressed="true"/>    <!-- 按下时的背景图片 -->    <item android:drawable="@drawable/a" android:state_checked="true" android:state_enabled="true"/>    <!-- 默认时的背景图片 -->    <item android:drawable="@drawable/ic_launcher"/></selector>

布局中设置按钮背景为btn_selected.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context=".MainActivity" >    <Button        android:id="@+id/btn_user_selected"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:background="@drawable/btn_selected" >    </Button></RelativeLayout>

更多相关文章

  1. android灵活布局
  2. Android学习之线性布局管理器
  3. android 学习 之 布局(下)LinearLayout,RelativeLayout,TableLayout,F
  4. 【Android】Android Layout Binder——根据layout布局文件自动生
  5. Android 去掉状态栏 去掉标题栏 沉浸式状态栏 状态栏重叠 布局重
  6. Android布局优化
  7. android布局基础及范例(二):人人android九宫格布局
  8. Android 软键盘在有scollview,纵向viewpager+recyclview实现列表,

随机推荐

  1. AndroidUI开源组件库BottomView 第三方自
  2. 27款Python 测试工具开源软件
  3. 如何在真机上调试Android应用程序(图文详
  4. Android(安卓)学习入门最佳Demo--自定义V
  5. Android(安卓)8.0后台执行限制
  6. React Native开源项目-F8 App环境搭建
  7. Android数据库SQLite增改查删操作演示
  8. 史上最详细的Android(安卓)Studio系列教
  9. Android(安卓)Studio的logcat窗口被拖出
  10. Android之Adapter用法总结(转载)