1

StyleMeの画像はstyle_linkです

これが画像です。このようなタブビュー画像の背景が必要です。選択されていない場合は白い画像が表示され、選択されている場合は緑色の画像が表示されます。

コードは次のとおりです。

Resources resources = getResources();
TabHost tabhost = getTabHost();
Intent one = new Intent().setClass(this, StyleMe.class);
TabSpec tb1=tabhost.newTabSpec("One").setIndicator("",resources.getDrawable
(R.drawable.style_link)).setContent(one); 
tabhost.addTab(tb1);
4

1 に答える 1

0

より良い解決策は、セレクターでバックグラウンドを使用することです。そのため、onTabChangedをチェックして、手動で更新する必要はありません。

private void initTabsAppearance(TabWidget tabWidget) {
    // Change background
    for(int i=0; i < tabWidget.getChildCount(); i++)
        tabWidget.getChildAt(i).setBackgroundResource(R.drawable.tab_bg);
}

tab_bgは、セレクターを使用して描画可能な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>

これがお役に立てば幸いです。

于 2013-03-01T03:53:36.693 に答える