立即注册 登录
逆天PCB论坛 返回首页

yuanxinfei的个人空间 https://bbs.ntpcb.com/?44609 [收藏] [复制] [RSS]

日志

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]

路过

雷人

握手

鲜花

鸡蛋

全部作者的其他最新日志

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 立即注册

Copyright ©2011-2024 NTpcb.com All Right Reserved.  Powered by Discuz! (NTpcb)

本站信息均由会员发表,不代表NTpcb立场,如侵犯了您的权利请发帖投诉

( 闽ICP备2024076463号-1 ) 论坛技术支持QQ群171867948 ,论坛问题,充值问题请联系QQ1308068381

平平安安
TOP
返回顶部