2015-09-28 55 views
3

我有一個背景爲白色的活動,並添加了一個switchcompat,但是當開關未處於活動狀態時(關閉),軌道不可見。所有可見的是拇指,因此對用戶來說它根本不是一個明顯的開關。當開關處於非工作位置時,如何使開關的軌跡可見?Android:在白色背景下跟蹤不可見的switchcompat

    <android.support.v7.widget.SwitchCompat 
         android:id="@+id/someswitchname" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignParentRight="true" 
         android:layout_alignParentEnd="true" 
         /> 
+1

偏離軌道的顏色與'android:colorForeground'類似,確保您的主題不會將其設置爲「白色」,或將其設置爲其他顏色。 – njzk2

+0

@ njzk2 - 感謝您的幫助。 android:colorForeground確實會改變軌道的顏色..但是我無法在較深的彩色軌道上放置一個淺色的拇指 - 而不管我在前景中設置了什麼,它堅持在較輕的軌道上設置較暗的拇指。任何想法,爲什麼這可能是? – Jon

+0

這可能是因爲你使用的主題。什麼是主題或你的活動? – njzk2

回答

3

做到這一點的方法是定義一個定製的主題是這樣的:

<style name="Custom.SwitchCompat.WhiteTrack" parent="Base.Widget.AppCompat.CompoundButton.Switch"> 
     <!-- Inactive track color(30% transparency) --> 
     <item name="android:colorForeground">[some color]</item> 
    </style> 

然後定義你的佈局主題是這樣的:

android:theme="@style/Custom.SwitchCompat.WhiteTrack" 

等就萬事大吉了。

相關問題