android 点击字体,图片背景效果一起变换Demo

运行效果:

点击前:


点击后:


这里我就不贴上所有的代码了,说一下他的思路:

1、分别为账号、背景图片(红色区域为一个linealayout,文字和向右侧的箭头是他里面的子View,必须为红色区域添加onclick事件)、还有向右侧的箭头符号添加一个效果文件(一下是其中一个文件的类容):

背景图片的效果:(setting_page_setting_item_background——sector.xml)

<?xmlversion="1.0"encoding="utf-8"?>

<selectorxmlns:android="http://schemas.android.com/apk/res/android">

<itemandroid:drawable="@drawable/setting_page_setting_item_background"android:state_pressed="true"/>

<itemandroid:drawable="@drawable/setting_page_setting_item_transparent"android:state_pressed="false"/>

</selector>

文字颜色的变换效果:(font_sector)

<?xmlversion="1.0"encoding="utf-8"?>

<selectorxmlns:android="http://schemas.android.com/apk/res/android">

<itemandroid:color="@color/white_text"android:state_pressed="true"/>

<itemandroid:color="@color/red_text"android:state_pressed="false"/>

</selector>

注意:文字的颜色要在Values文件夹下创建一个color.xml的文件,类容如下:

<?xmlversion="1.0"encoding="utf-8"?>

<resources>

<colorname="transparent_background">#50000000</color>

<color name="black_text">#000000</color>

<color name="white_text">#ffffff</color>

<color name="red_text">#c35363</color>

<colorname="dialogbackgournd">#EE000000</color>

</resources>



为你要添加效果的控件添加这个效果:

为字体添加效果:

<TextViewandroid:id="@+id/accont_text"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="账号"

android:gravity="left"

android:paddingLeft="17sp"

android:layout_gravity="center"

android:textColor="@drawable/font_sector"

android:textSize="17sp"

android:layout_weight="1"/>

为图片添加效果:

<ImageViewandroid:id="@+id/accont_img"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginRight="10dp"

android:background="@drawable/setting_page_to_next_page_sector"/>


好了,如果你好没有懂,这里有个Demo可下载:

http://download.csdn.net/download/lyhdream/5179710





更多相关文章

  1. android 5.0和6.0后新增的控件总结
  2. android ICS原生态Browser上增加对WML的支持
  3. Android(安卓)UI界面(分辨率)最实用的的两种适配模式(含AutoSize
  4. android sqlit数据库升级,添加字段
  5. Android(安卓)仿Iphone文件夹分裂效果
  6. Android轻松搞定Dialog提示动画效果
  7. Android开发学习笔记:Intent的简介以及属性的详解
  8. android图文弹幕
  9. 【Android】Animation之震动效果动画在登录Activity上的应用

随机推荐

  1. Android(安卓)椭圆路径 长按暂停动画的实
  2. android 中无法使用LOGE显示log
  3. 文本中的值的保存与恢复
  4. Android(安卓)Studio jcenter集成butterk
  5. Android(安卓)studio使用教程
  6. 1 android 人脸识别
  7. Android(安卓)Content Provider Guides
  8. 模拟获取android root权限
  9. 横竖屏切换不重启activity的方法
  10. Android(安卓)premission 访问权限代码