`

android中button通过XML来改变它背景图片

 
阅读更多

使用XML实现按钮改变焦点设置背景图,获得焦点时,获得焦点并按下,失去焦点时,默认时...

 

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 获得焦点时 -->
<item
android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/onfocusimage2"
/>
<!-- 获得焦点并按下 -->
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/clickimage2"
/>
<!-- 失去焦点时 -->
<item
android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/clickimage2"
/>
<!-- 默认时 -->
<item android:drawable="@drawable/defaultimage2"/>
</selector>

 

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/settingsLayoutId"
    android:gravity="center"
    >   
<!--这个android:background就读取自己定义的XML文件-->
     <Button
        android:background="@anim/imgbutton"
        android:text="@string/app_pic"
        android:id="@+id/imagesBut"
        style="@style/settingsBut"
        /> 
</LinearLayout>

  完成!

2
0
分享到:
评论

相关推荐

    Android Button按钮点击背景和文字变化操作

    按钮背景图片放在 drawable/background_button.xml &lt;?xml version=1.0 encoding=utf-8?&gt; &lt;selector xmlns:android=http://schemas.android.com/apk/res/android&gt; &lt;item android:drawable=@drawable

    CircularProgressButton

    * ColorStateList对象可以在XML中定义,像color一样使用,它能根据它应用到的View对象的状态实时改变颜色 * 当每次状态改变时,StateList都会从上到下遍历一次,第一个匹配当前状态的item将被使用——选择的过程...

    新版Android开发教程.rar

    Android Android Android Android 开发背景 � 计算技术、无线接入技术的发展,使嵌入式系统逐渐有能力对桌面系统常规业务进行支持。 � 谷歌长期以来奉行的移动发展战略:通过与全球各地的手机制造商和移动运营商...

    Android selector的实例详解

    例如,一个Button有几个不同的状态(按压,获取焦点等等),这种情况下,通过使用 state list drawable,你就可以实现在不同的状态下使用不同的背景图片。 你可以在一个XML文件中描述state list。通过在根节点...

    疯狂Android讲义源码

     2.3.2 按钮(Button)与图片按钮(ImageButton)组件的功能和  用法 66  2.3.3 使用9Patch图片作为按钮背景 68  2.3.4 单选按钮(RadioButton)和复选  框(CheckBox)介绍与应用 69  2.3.5 状态开关按钮...

    Google Android SDK开发范例大全(PDF高清完整版1)(4-1)

    4.23 动态放大缩小ImageView里的图片——运用Matrix对象来缩放图文件 4.24 动态旋转图片——Bitmap与Matrix旋转ImageView 4.25 猜猜我在想什么——RadioButtonID 4.26 离开与关闭程序的弹出窗口——对话窗口上的ICON...

    Google Android SDK开发范例大全(PDF完整版4)(4-4)

    4.23 动态放大缩小ImageView里的图片——运用Matrix对象来缩放图文件 4.24 动态旋转图片——Bitmap与Matrix旋转ImageView 4.25 猜猜我在想什么——RadioButtonID 4.26 离开与关闭程序的弹出窗口——对话窗口上的ICON...

    Google Android SDK开发范例大全(PDF高清完整版3)(4-3)

    4.23 动态放大缩小ImageView里的图片——运用Matrix对象来缩放图文件 4.24 动态旋转图片——Bitmap与Matrix旋转ImageView 4.25 猜猜我在想什么——RadioButtonID 4.26 离开与关闭程序的弹出窗口——对话窗口上的ICON...

    Google Android SDK开发范例大全的目录

    4.23 动态放大缩小ImageView里的图片——运用Matrix对象来缩放图文件 4.24 动态旋转图片——Bitmap与Matrix旋转ImageView 4.25 猜猜我在想什么——RadioButtonID 4.26 离开与关闭程序的弹出窗口——对话窗口上的ICON...

    Google Android SDK开发范例大全(完整版附部分源码).pdf

    4.23 动态放大缩小ImageView里的图片——运用Matrix对象来缩放图文件 4.24 动态旋转图片——Bitmap与Matrix旋转ImageView 4.25 猜猜我在想什么——RadioButtonID 4.26 离开与关闭程序的弹出窗口——对话窗口上的...

    疯狂Android讲义.part1

    2.3.2 按钮(Button)与图片按钮(ImageButton)组件的功能和 用法 66 2.3.3 使用9Patch图片作为按钮背景 68 2.3.4 单选按钮(RadioButton)和复选 框(CheckBox)介绍与应用 69 2.3.5 状态开关按钮(ToggleButton)...

    Google Android SDK 开发范例大全01

    4.23 动态放大缩小ImageView里的图片——运用Matrix对象来缩放图文件 4.24 动态旋转图片——Bitmap与Matrix旋转ImageView 4.25 猜猜我在想什么——RadioButtonID 4.26 离开与关闭程序的弹出窗口——对话窗口上的ICON...

    Google Android SDK 开发范例大全02

    4.23 动态放大缩小ImageView里的图片——运用Matrix对象来缩放图文件 4.24 动态旋转图片——Bitmap与Matrix旋转ImageView 4.25 猜猜我在想什么——RadioButtonID 4.26 离开与关闭程序的弹出窗口——对话窗口上的ICON...

    Google+Android+SDK开发范例大全

    4.22 加载手机磁盘里的图文件——使用decodeFile方法 4.23 动态放大缩小ImageView里的图片——运用Matrix对象来缩放图文件 4.24 动态旋转图片——Bitmap与Matrix旋转ImageView 4.25 猜猜我在想什么——...

    Android开发资料合集-World版!

    附录1、XML布局中的常用属性 378 1.通用属性 378 2.Edit Text部分属性 381 3.layout_alignParentRight android:paddingRight 384 附录2、INTENT ACTION 385 附录3、ANDROID的动作、广播、类别等标志 387 ★★★...

Global site tag (gtag.js) - Google Analytics