TabWidget에서 추가되는 Tab의 Background변경하기
Tab마다 View를 얻어와서 직접 BackgroundDrawable을 지정하고
아래 막대부분은 reflection을 이용하여 꽁수로 바꿔치기 한다
tab_indicator.xml, tab_bar_left.xml, tab_bar_right.xml 내용은 <selector>로 정의
private void changeTabWidgetStyle(TabWidget tw){
for (int i = 0; i < tw.getChildCount(); i++) {
View v = tw.getChildAt(i);
v.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_indicator));
}
Field mBottomLeftStrip;
Field mBottomRightStrip;
try {
mBottomLeftStrip = tw.getClass().getDeclaredField("mBottomLeftStrip");
mBottomRightStrip = tw.getClass().getDeclaredField("mBottomRightStrip");
if(!mBottomLeftStrip.isAccessible()) {
mBottomLeftStrip.setAccessible(true);
}
if(!mBottomRightStrip.isAccessible()){
mBottomRightStrip.setAccessible(true);
}
mBottomLeftStrip.set(tw, getResources().getDrawable(R.drawable.tab_bar_left));
mBottomRightStrip.set(tw, getResources().getDrawable(R.drawable.tab_bar_right));
} catch (Exception e) {
e.printStackTrace();
}
}
tab_indicator.xml 예
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item android:state_focused="false"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/tab_unselected" />
<item android:state_focused="false"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/tab_selected" />
<!-- Focused states -->
<item android:state_focused="true"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/tab_focus" />
<item android:state_focused="true"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/tab_focus" />
<!-- Pressed -->
<item android:state_pressed="true" android:drawable="@drawable/tab_press" />
</selector>
댓글을 달아 주세요
음... 아직은 내가 아무것도 몰라서;;;
이거 봐도 무슨 말인지 모르겠다 ㅋㅋ
지금 열심히 책봐야지
ㅎㅎ 별로 쓸일없는거예요 ㅋ; 열공~!!
별로 쓸일이 없어도...
나중에 궁금한거 있으면 물어볼께 ㅋㅋㅋ
나중에 모른척하고 안갈쳐주면 안데~ㅋㅋ
ㅎㅎ;; 알면 갈쳐주는거고 모르면 모르는거고 머; ㅎㅎ
블로그로 퍼갈게요~~ 비공개로
ㅎㅎ 네~