2015-06-20 117 views
4

當我安裝了「22.2.0 Android的設計庫」的tabBackground屬性TabLayout(android.support.design.widget.TabLayout)兩個問題出現:Android的設計庫TabLayout背景問題

  • 的連鎖反應在選項卡中丟失
  • 的標籤指示消失。

這發生在兩個棒棒糖和奇巧設備。

沒有tabBackground設置,既連鎖反應和標籤指示的工作,但後臺有一個默認的顏色,是從商工具欄,這是不完全符合材料設計原則不同。

請找到下面的XML:

<android.support.design.widget.TabLayout 
     android:id="@+id/tabLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:tabMode="fixed" 
     app:tabGravity="fill" 
     app:tabBackground = "?attr/colorPrimary" /> 

回答

14

使用android:background="?attr/colorPrimary"而不是app:tabBackground = "?attr/colorPrimary"

如果你有黑暗原色,你可能還需要主題更改爲ThemeOverlay.AppCompat.Dark。這使文本和波紋顏色變白。

完整的示例:

<android.support.design.widget.TabLayout 
     android:id="@+id/tabLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:tabMode="fixed" 
     app:tabGravity="fill" 
     android:background="?attr/colorPrimary" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark" /> 
+0

大。它現在可以工作,只是我沒有KitKat設備上的連鎖反應。你知道在Android的設計庫TabLayout的連鎖反應是否應該被移植到奇巧「?謝謝。 – u2gilles

+0

不,我知道的。我覺得漣漪只在5.0及以上的設計庫工作。 – Huby

+0

' android:background =「@ color/someColor」'也適用於'android:theme =「@ style/ThemeOverlay.AppCompat.Dark」'如果有人想知道 – ashishmohite