TextView 字体颜色选择器结合 ViewPager 的使用
2016-03-10 17:42
330 查看
1.res/color/textcolor.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:color="@color/textColor_selected"/>
<item android:state_selected="false" android:color="@color/textColor_unselected"/>
</selector>
2.res/values/strings
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Hello</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<color name="textColor_selected">#FBFDFE</color>
<color name="textColor_unselected">#7FBBEC</color>
</resources>
3.search.xml
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginLeft="60dp"
android:layout_marginTop="10dp"
android:text="内容"
android:textColor="@color/textcolor"
android:textSize="25sp" />
<TextView
android:id="@+id/person"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginBottom="15dp"
android:layout_marginRight="60dp"
android:layout_marginTop="10dp"
android:text="人"
android:textColor="@color/textcolor"
android:textSize="25sp" />
</RelativeLayout>
4.在 ViewPager 选择器中设置
viewPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
// 设置滑动页显示光标
textView1.setSelected(arg0 == 0 ? true : false);
textView2.setSelected(arg0 == 1 ? true : false);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
});
5.效果图:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:color="@color/textColor_selected"/>
<item android:state_selected="false" android:color="@color/textColor_unselected"/>
</selector>
2.res/values/strings
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Hello</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<color name="textColor_selected">#FBFDFE</color>
<color name="textColor_unselected">#7FBBEC</color>
</resources>
3.search.xml
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginLeft="60dp"
android:layout_marginTop="10dp"
android:text="内容"
android:textColor="@color/textcolor"
android:textSize="25sp" />
<TextView
android:id="@+id/person"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginBottom="15dp"
android:layout_marginRight="60dp"
android:layout_marginTop="10dp"
android:text="人"
android:textColor="@color/textcolor"
android:textSize="25sp" />
</RelativeLayout>
4.在 ViewPager 选择器中设置
viewPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
// 设置滑动页显示光标
textView1.setSelected(arg0 == 0 ? true : false);
textView2.setSelected(arg0 == 1 ? true : false);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
});
5.效果图:
相关文章推荐
- 构造函数
- 经典SQL语句大全(技巧篇)
- ExtJS自定义css样式
- 一个小问题引发的"Listview里有多个Edittext,点击一个全部都高亮"
- 【风宇冲】Unity3D性能优化:DrawCall优化
- UVa 11234 - Expressions
- Spring mvc实现上传文件进度条
- 数据结构与算法(c语言) 学习笔记——第三章练习
- DOM对象和jQuery对象的区别
- Intellij13 IDEA常用快捷键 (mac 10.5 +),优化,使用出现的问题汇总
- spring在web工程和普通java工程使用时候区别
- android.database.sqlite.SQLiteException: near "where": syntax error (code 1): ,
- VR就是下一个浪潮--2016 (GMGC) 全球移动游戏大会观后感
- Android常见监听事件
- 经典SQL语句大全(提升篇)
- BaseViewController中默认设置左右导航栏按钮代码
- Oracle Using Flashback Drop and Managing the Recycle Bin
- 算法导论:第15章 动态规划_2矩阵链乘法
- Android断点续传
- SIP注册