2010-06-12 5 views
8

나는 안드로이드 탭을 공식 TWitter 앱과 같이 평평하게 보이기를 원합니다. 기본 (밝은) 테마를 덮어 쓰고 스타일/테마 정의를 사용하여 탭의 배경 이미지를 변경하려면 어떻게합니까?Android에서 탭 스타일을 변경하는 방법은 무엇입니까?

+0

내가 지금까지 본 것입니다 가장 우아한 해결책 : http://stackoverflow.com/questions/3078081/setting-a-global-style-for-views-in-android/3166865#3166865 –

답변

16

코드를 통해 탭을 조정할 수 있습니다. 여기에 내 애플리케이션에서 발췌 한 내용이 있지만 배경 이미지 대신 테마를 직접 할당 할 수도 있습니다. (나는 xml 속성을 통해 아직 방법을 사용하지 않았지만 어쨌든 사용 가능한지 확실하지 않다.)

private void initTabs() { 
    tabs = (TabHost) findViewById(R.id.tabhost); 
    tabs.setup(); 
    tabs.setBackgroundResource(R.drawable.bg_midgray); 

    TabHost.TabSpec spec; 

    // Location info 
    txtTabInfo = new TextView(this); 
    txtTabInfo.setText("INFO"); 
    txtTabInfo.setPadding(0, 5, 0, 0); 
    txtTabInfo.setTextSize(11); 

    txtTabInfo.setBackgroundResource(R.drawable.bg_tab_left_active_right_inactive); 
    txtTabInfo.setTextColor(Color.DKGRAY); 
    txtTabInfo.setGravity(Gravity.CENTER_HORIZONTAL); 
    txtTabInfo.setHeight(39); 
    spec = tabs.newTabSpec("tabInfo"); 
    spec.setContent(R.id.tabInfo); 
    spec.setIndicator(txtTabInfo); 
    tabs.addTab(spec); 
    ... 
} 
+0

사양. setIndicator (txtTabInfo); 허용되지 않습니다. 컴파일러는이 줄에서 오류를 발생시킵니다. – sachin

0

XML로도 만들 수 있으며 앱의 모든 탭에 대한 글로벌 테마를 만들고 정의 할 수 있습니다. 추가 정보를 원하시면 여기 위젯 테마를 만드는 방법에있다 :

3

http://developer.android.com/guide/topics/ui/themes.html 나는 그런 그들을 설정 탭을 반복 tab_background.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android" > 
     <item android:state_selected="true" android:drawable="@drawable/tab_bg_selected" /> 
     <item android:drawable="@drawable/tab_bg_normal" /> 
    </selector> 

내 당김의 다음과 같은 정의를 사용했다.

TabWidget tabWidget = tabHost.getTabWidget(); 

for(int i=0; i<tabWidget.getChildCount(); i++) 
    tabWidget.getChildAt(i).setBackgroundResource(R.drawable.tab_background); 
관련 문제