android 点击字体,图片背景效果一起变换Demo
android ?點(diǎn)擊字體,圖片背景效果一起變換Demo
運(yùn)行效果:
點(diǎn)擊前:
點(diǎn)擊后:
這里我就不貼上所有的代碼了,說一下他的思路:
1、分別為賬號(hào)、背景圖片(紅色區(qū)域?yàn)橐粋€(gè)linealayout,文字和向右側(cè)的箭頭是他里面的子View,必須為紅色區(qū)域添加onclick事件)、還有向右側(cè)的箭頭符號(hào)添加一個(gè)效果文件(一下是其中一個(gè)文件的類容):
背景圖片的效果:(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文件夾下創(chuàng)建一個(gè)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>
為你要添加效果的控件添加這個(gè)效果:
為字體添加效果:?
<TextViewandroid:id="@+id/accont_text"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:text="賬號(hào)"
? ? ? ? ? ? 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"/>
好了,如果你好沒有懂,這里有個(gè)Demo可下載:
http://download.csdn.net/download/lyhdream/5179710
總結(jié)
以上是生活随笔為你收集整理的android 点击字体,图片背景效果一起变换Demo的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android ViewPager 实
- 下一篇: Viewpager中改变PagerTab