77.s1-9patch图和状态选择器图片点击切换色彩(状态切换)的特效

    xiaoxiao2021-03-25  87

    .9.png(9-Patch)

    通过黑色边线来描述图片的拉伸情况和填充文字的方式

    上边线表示图片水平拉伸,左边线表示垂直拉伸

    右边线表示垂直填充区域,下边线表示水平填充区域

    状态选择器的使用:图片点击的时候显示不同的图片,使用selector来实现

    图片点击切换色彩的特效

    <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:background="@drawable/button" android:text="下一步" />

    这时候需要在res目录下创建是一个drawable的文件夹,然后创建一个button.xml的文件(和上面的button一一对应)

    button.xml,里面有三个item分别对应的是按键时候焦点落上去的时候以及平时的状态的时候的图片,同时需要往图片库里面放三个对应的图片,实现点击和聚焦等状态图片变化

    res/drawable/button.xml

    <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/button_pressed" android:state_pressed="true"/> <!-- pressed --> <item android:drawable="@drawable/button_pressed" android:state_focused="true"/> <!-- focused --> <item android:drawable="@drawable/button_normal"/> <!-- default --> </selector>

     

    转载请注明原文地址: https://ju.6miu.com/read-17764.html

    最新回复(0)