안드로이드 개발 질문/답변
(글 수 45,052)
아래와 같이 탭을 구성했습니다.
그런데, 탭을 선택했을 경우와 아닌경우 이미지 아이콘을 다르게 보여주려고 하는데요?
어떻게 해야 하나요?
final TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab1")
.setIndicator("홈", getResources().getDrawable(R.drawable.top_menu_01_out))
.setContent(new Intent(this, Mornitoring.class)));
2010.02.25 14:44:15
이런 방식으로도 가능 하실 것 같습니다. http://stackoverflow.com/questions/36881/updating-android-tab-icons
Tab에 설정된 indicator 에 바로 접근 가능한 API 는 제공되지 않지만, 약간의 꽁수로 getTabWidget().getChildTabViewAt(0) 를 이용하신다음에 해당 View 의 Background 를 변갱하거나 State 값을 변경하면 가능하지 않을까요?




<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>