0

このアクション バー スタイル ジェネレーターを使用して、アプリケーションのテーマを作成しました。

http://jgilfelt.github.io/android-actionbarstylegenerator/

タブの色をオレンジに設定しましたが、レイアウトのタブには影響しません。

私のレイアウトは次のようになります。

<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@android:id/tabhost" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:orientation="horizontal" />

        <FrameLayout
            android:id="@+id/tabFrameLayout"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />
    </LinearLayout>
</android.support.v4.app.FragmentTabHost>

スタイル ファイルとマニフェスト ファイルに含まれている他のものを次に示します。

マニフェスト ファイル

android:theme="@style/Theme.Silence"

styles_silence.xml

<style name="Theme.Silence" parent="android:Theme.Holo.Light">
    <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Silence</item>
    ...
</style>
...
<style name="ActionBarTabStyle.Silence" parent="@android:style/Widget.Holo.Light.ActionBar.TabView">
    <item name="android:background">@drawable/tab_indicator_ab_silence</item>
</style>

tab_indicator_ab_silence.xml (これは、先ほどリンクしたプログラムによって生成されます)

<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="@android:color/transparent" />
    <item android:state_focused="false" android:state_selected="true"  android:state_pressed="false" android:drawable="@drawable/tab_selected_silence" />

    <!-- Focused states -->
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_focused_silence" />
    <item android:state_focused="true" android:state_selected="true"  android:state_pressed="false" android:drawable="@drawable/tab_selected_focused_silence" />

    <!-- Pressed -->
    <!--    Non focused states -->
    <item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_silence" />
    <item android:state_focused="false" android:state_selected="true"  android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_silence" />

    <!--    Focused states -->
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_silence" />
    <item android:state_focused="true" android:state_selected="true"  android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_silence" />
</selector>

このドキュメントを確認しましたが、すべて問題ないようです。何が間違っている可能性がありますか?

4

2 に答える 2

4

何が間違っている可能性がありますか?

そのツールは に存在するタブのスタイルを生成しますが、別のスタイルが関連付けられているActionBar通常のタブを (標準を介して) 使用しています。そのスタイルは、スタイル style を指す属性TabWidgetによってテーマで表されます。tabWidgetStyleWidget.(Holo).TabWidget

残念ながらWidget.TabWidget、テーマのスタイルを介して背景を変更することはできません (また、これを管理する属性としてのタブ レイアウトも非表示になります) が、新しいレイアウトをタブ インジケーターとして割り当て、そこにセレクターを配置することで手動で行うことができます:

fragmentTabHost.addTab(fragmentTabHost.newTabSpec("tabText").setIndicator(buildTabLayout("tabText")), YourFragmentClass.class, null);

buildTabLayout()このようなメソッドはどこにありますか:

private View buildTabLayout(String tag) {
    View tab = getLayoutInflater().inflate(R.layout.new_tab_layout, null);      
    return tab;
}

レイアウトは次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/tab_indicator_ab_silence" // or you could have a style attribute
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" android:text="simple"/>

于 2013-10-28T14:47:02.137 に答える