您的位置:首页 > 其它

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.效果图:



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: