0
내가 그것에 대해 사용자 Tab 키를 누르 내가 tabhost 이하로 사용했을 경우 아래
tabhost변경 아이콘을 tabhost 안드로이드
에 클릭이private void setTabs() {
addTab("Home", TabHome.class, R.drawable.home);
addTab("Performers", TabPerformers.class, R.drawable.performers);
addTab("Tickets", TabTickets.class, R.drawable.tickets);
addTab("Info", TabInfo.class, R.drawable.info);
}
private void addTab(String labelId, Class<?> c, int drawableId) {
tabHost = getTabHost();
Intent intent = new Intent(this, c);
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);
tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
icon = (ImageView) tabIndicator.findViewById(R.id.icon);
icon.setImageResource(drawableId);
spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);
}
내가 탭의 아이콘을 변경하려는 소스 코드가있는 경우 아이콘을 변경하려면
이벤트
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
if (tabId.equals("tabHome")) {
하지만
도 tab_indicater.xml 파일이 성공하지 수 하지만 단지 배경에서 수 변경하려면 아래
는 XML 코드<?xml version="1.0" encoding="utf-8"?>
아래
<!-- Non focused states -->
<item android:drawable="@drawable/tab_unselected" android:state_focused="false" android:state_pressed="false" android:state_selected="false"/>
<item android:drawable="@drawable/tab_bg_selector" android:state_focused="false" android:state_pressed="false" android:state_selected="true"/>
<!-- Focused states -->
<item android:drawable="@drawable/tab_bg_selector" android:state_focused="true" android:state_pressed="false" android:state_selected="false"/>
<item android:drawable="@drawable/tab_bg_selector" android:state_focused="true" android:state_pressed="false" android:state_selected="true"/>
<!-- Pressed -->
<item android:drawable="@drawable/tab_bg_selector" android:state_pressed="true" android:state_selected="true"/>
<item android:drawable="@drawable/tab_press" android:state_pressed="true"/>
입니다
촬영 화면입니다 아이콘되지 않습니다 우리가 어떤 하나 개의 탭을 클릭하면그것의 아이콘을 TabSpec 아이콘을 변경할 수있는 간단한 방법은 없습니다 ...
하지만이 아이콘이이 탭에 해당하고 해당 아이콘에 해당 아이콘이 어떻게 구별 될 수 있습니까? –
간단한 다른 탭에 다른 드로어 블을 사용하십시오 :) – iceman
iceman :) 감사합니다. –