티스토리 뷰
TabWidget에서 추가되는 Tab의 Background변경하기
Tab마다 View를 얻어와서 직접 BackgroundDrawable을 지정하고
아래 막대부분은 reflection을 이용하여 꽁수로 바꿔치기 한다
tab_indicator.xml, tab_bar_left.xml, tab_bar_right.xml 내용은 <selector>로 정의
tab_indicator.xml 예
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();
}
}
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>
<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>
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 포스트크로싱
- 음악
- 일어일기
- 잡담
- 신주쿠
- 사진
- 도쿄
- 공연
- 일본
- 코이데 케이스케
- android
- 인디
- Linux
- 일기
- 노래
- 영화
- Mac
- 서울숲별밤축제
- 여행
- 진해
- 락
- epik high
- 드라마
- Java
- 책
- 에픽하이
- 야마다 타카유키
- 안드로이드
- 아사가야
- postcrossing
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
글 보관함