タブバーの背景を白に設定する必要があります。また、選択したタブの背景色をピンクに設定し、残りのタブ (選択されていないタブ) の背景色をblueに設定する必要があります。私の既存のコードを以下に示します。その中で何を変更する必要がありますか?
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:background="#ffffffff"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffffff" >
<TabWidget
android:id="@android:id/tabs"
android:background="@drawable/tabicon"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:background="#ffffffff"
android:layout_height="fill_parent"/>
</LinearLayout>
</TabHost>
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_v4" />
<item android:state_focused="false" android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/tab_selected_v4" />
<!-- 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>
tab_unselected_v4.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true">
<shape>
<gradient android:startColor="#FFFFFF"
android:endColor="#FFFFFF"
/>
</shape>
</item>
</selector>
tab_focus.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- Gradient BgColor for listrow Selected -->
<gradient
android:startColor="#5e8fb7"
android:centerColor="#5e8fb7"
android:endColor="#5e8fb7"
/>
</shape>
tab_selected.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- Gradient Bg for listrow -->
<gradient
android:startColor="#5e8fb7"
android:centerColor="#5e8fb7"
android:endColor="#5e8fb7"
/>
</shape>
tab_press.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- Gradient Bg for listrow -->
<gradient
android:startColor="#FFFFFF"
android:centerColor="#FFFFFF"
android:endColor="#FFFFFF"
/>
</shape>
編集: コードの下に追加しました。現在、背景色が白に変わります。しかし、選択したアイテムと選択していないアイテムの色が必要な色に設定されていません。助けてください。良い解決策を教えてください。
tabicon.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true">
<shape>
<gradient android:startColor="#FFFFFF"
android:endColor="#FFFFFF"
android:angle="90"
/>
</shape>
</item>
<item android:state_focused="true">
<shape>
<gradient android:startColor="#FFFFFF"
android:endColor="#FFFFFF"
android:angle="90" />
</shape>
</item>
</selector>
Javaコードの下にも追加されました:
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
{
tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tab_indicator);
}
tabHost.getTabWidget().setCurrentTab(0);
tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.tab_indicator);
}
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
{
tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tab_indicator);
}
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundResource(R.drawable.tab_indicator);
}
}
編集:
ここでは、選択した背景色を設定する必要があり、選択されていない背景色は正常に設定されています。
ここで、1 つの実装が必要です。
最初のタブの幅が 2 番目と 3 番目のタブの幅よりも大きくなっています。私を助けてください。
ここでは、ダッシュボード タブが注文および顧客タブよりも大きくなっています。助けてください。これを設計および開発するにはどうすればよいですか。これは私の出力です:
o/p が必要な場合は、下の画像のようになります。
編集:
ここで、私のstyle.xmlでこのコードを使用する必要があります:
<style name="CustomTheme" parent="@android:style/Theme">
<item name="android:tabWidgetStyle">@style/CustomTabWidget</item>
</style>
<style name="CustomTabWidget" parent="@android:style/Widget.TabWidget">
<item name="android:textAppearance">@style/CustomTabWidgetText</item>
</style>
<style name="CustomTabWidgetText"
parent="@android:style/TextAppearance.Widget.TabWidget">
<item name="android:textSize">20sp</item>
<item name="android:textStyle">bold</item>
</style>
その後、AndroidManifest.xml ファイルに以下の行を追加します。
<activity android:name="MyTabActivity" android:theme="@style/CustomTheme">
これで、タブホストでフォントサイズと色とスタイルを正常に変更できました。