有时候希望textview press下去之后,能够动态的调整其背景颜色或者效果,像listview中的条目被按中之后的蓝光效果,以下是通过xml来实现这个功能,
1,res/drawable下建立一个textview_style.xml文件用来定义textview的两种风格
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/blue" />
<item android:drawable="@color/transparent_background" />
</selector>
2,res/values下建立colcors.xml文件,定义color的值,
<resources>
<color name="transparent_background">#ffffffff</color>
<color name="blue">#ff87cefa</color>
</resources>
3,定义textview,其中background使用定义的style
<TextView
android:id="@+id/new_playlist"
android:layout_width="fill_parent"
android:layout_height="100px"
android:textColor="#2b2b2b"
android:textSize="32px"
android:textStyle="bold"
android:text="@string/new_playlist"
android:singleLine="true"
android:gravity="center_vertical"
android:background="@drawable/textview_style"
/>
以上就已经实现了textview动态效果的功能
最后
以上就是辛勤香水最近收集整理的关于textview动态调整背景颜色的全部内容,更多相关textview动态调整背景颜色内容请搜索靠谱客的其他文章。
发表评论 取消回复