在xml里可以简单的通过设置 textview selector 就可以实现,但是在代码中实现则需要
textView.setTextColor(getResources().getColorStateList(R.color.text_selector_color));来设置。
tab切换时底部导航布局
<LinearLayout android:id="@+id/rb_integral_or_energy_0" android:layout_width="0dp" android:layout_height="match_parent" android:background="@color/color_f4f4f4" android:layout_weight="1" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:gravity="center" android:text="聊天" /> <TextView android:layout_width="match_parent" android:layout_height="@dimen/size1" /> </LinearLayout>
切换到该tab ,tab的字体,底部横线都变色。简单设置外部布局
rbIntegralOrEnergy0.setSelected(true);
反之 setSelected(false).