android中如何设置图片按钮的点击效果
已有 504 次阅读2016-7-28 16:21
[backcolor=#ffffff][color=#454545][font=arial, 宋体, sans-serif, tahoma, ]顶楼上,xml里图片设为selector,自定义一个selector指明对应的两张图片素材就ok了[/font][/color][/backcolor]
[backcolor=#ffffff][color=#454545][font=arial, 宋体, sans-serif, tahoma, ]举个例子:[/font][/color][/backcolor]
[backcolor=#ffffff][color=#454545][font=arial, 宋体, sans-serif, tahoma, ]在drawable里定义一个文件叫aaa_selector[/font][/color][/backcolor]
[backcolor=#ffffff][color=#454545][font=arial, 宋体, sans-serif, tahoma, ]<?xml version="1.0" encoding="utf-8"?> [/font][/color][/backcolor]
[backcolor=#ffffff][color=#454545][font=arial, 宋体, sans-serif, tahoma, ]<selector xmlns:android="[/font][/color][/backcolor][url]http://schemas.android.com/apk/res/android[/url][backcolor=#ffffff][color=#454545][font=arial, 宋体, sans-serif, tahoma, ]"> [/font][/color][/backcolor]
[backcolor=#ffffff][color=#454545][font=arial, 宋体, sans-serif, tahoma, ]<item android:state_pressed="false"[/font][/color][/backcolor]
[backcolor=#ffffff][color=#454545][font=arial, 宋体, sans-serif, tahoma, ]android:drawable="@drawable/mainscreen_activity_button_02_save"/>[/font][/color][/backcolor]
[backcolor=#ffffff][color=#454545][font=arial, 宋体, sans-serif, tahoma, ]<item android:state_pressed="true"[/font][/color][/backcolor]
[backcolor=#ffffff][color=#454545][font=arial, 宋体, sans-serif, tahoma, ]android:drawable="@drawable/mainscreen_activity_button_02_save_down"/>[/font][/color][/backcolor]
[backcolor=#ffffff][color=#454545][font=arial, 宋体, sans-serif, tahoma, ]</selector>[/font][/color][/backcolor]
[backcolor=#ffffff][color=#454545][font=arial, 宋体, sans-serif, tahoma, ]然后在xml文件里引用[/font][/color][/backcolor]
[backcolor=#ffffff][color=#454545][font=arial, 宋体, sans-serif, tahoma, ]<Button[/font][/color][/backcolor]
[backcolor=#ffffff][color=#454545][font=arial, 宋体, sans-serif, tahoma, ]android:id="@+id/button_save"[/font][/color][/backcolor]
[backcolor=#ffffff][color=#454545][font=arial, 宋体, sans-serif, tahoma, ]android:layout_width="wrap_content"[/font][/color][/backcolor]
[backcolor=#ffffff][color=#454545][font=arial, 宋体, sans-serif, tahoma, ]android:layout_height="wrap_content"[/font][/color][/backcolor]
[backcolor=#ffffff][color=#454545][font=arial, 宋体, sans-serif, tahoma, ]android:layout_marginLeft="10dp"[/font][/color][/backcolor]
[backcolor=#ffffff][color=#454545][font=arial, 宋体, sans-serif, tahoma, ]android:layout_marginTop="50dp"[/font][/color][/backcolor]
[backcolor=#ffffff][color=#454545][font=arial, 宋体, sans-serif, tahoma, ]android:background="@drawable/aaa_selector" />[/font][/color][/backcolor]