TabLayout Custom View View 안에있는 TextView Selected 안될때 해결법!
2021. 2. 25. 16:02ㆍ모바일/Android_Java
TabLayout Custom View View 안에있는 TextView Selected 안될때 해결법!
해결법
xml
- drawable/tab_title_color
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="@color/color04" />
<item android:state_selected="true" android:color="@color/color04" />
<item android:state_focused="true" android:color="@color/color04" />
<item android:color="@color/color02" />
</selector>
- Layout/design_tab_button.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tab_button"
android:layout_width="match_parent"
android:layout_height="@dimen/dimen_35"
android:clickable="true" >
<TextView
android:id="@+id/tab_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="@drawable/hm_tab_title_color"
android:gravity="center"
android:textSize="15sp"
android:textStyle="bold"
android:singleLine="true"
android:layout_centerInParent="true"
android:duplicateParentState="true" />
<View
android:id="@+id/tab_selected_under_line"
android:layout_width="match_parent"
android:layout_height="@dimen/dimen_4"
android:background="@color/hm_tab_under_line_color"
android:visibility="gone"
android:layout_alignParentBottom="true"
android:duplicateParentState="true" />
<View
android:id="@+id/tab_unselected_under_line"
android:layout_width="match_parent"
android:layout_height="@dimen/dimen_1"
android:background="@color/color05"
android:layout_alignParentBottom="true"
android:duplicateParentState="true" />
</RelativeLayout>
자바코드
for(int i=0; i<TAB_TITLES.length;i++){
tabs.getTabAt(i).setCustomView(createTabView(TAB_TITLES[i]));
ColorStateList colorStateList = tabs.getTabTextColors();
TextView textView = tabs.getTabAt(i).getCustomView().findViewById(R.id.tab_name);
textView.setTextColor(colorStateList);
}
'모바일 > Android_Java' 카테고리의 다른 글
[Android] onNewIntent, onSaveInstanceState (0) | 2021.03.10 |
---|---|
[android] theme, attr, style, color ,values 정리 (0) | 2021.02.26 |
[안드로이드] You need to use a Theme.AppCompat theme (or descendant) with this activity (0) | 2021.02.25 |
CollapsingTollbar 스크롤 하면서 아이콘 위치 변경하기 (0) | 2021.01.12 |
[카카오페이 메인 클론코딩 2] onslide , onStateChanged, setalpha(블러처리/ 흐리게 하면서 사라지게함), scaleX(화면이 커지고 작아지고)구현 (0) | 2021.01.10 |