2013-05-10 155 views
0

我在更改項目中切換視圖的樣式時遇到問題,無法弄清楚我所做的錯誤或缺失......我的項目在任何地方都使用了全息圖。當使用Holo Everywhere時無法更改Android切換樣式

我無法更改文字,拇指或曲目。我已經嘗試直接從xml應用android:thumb和android:track drawables,但沒有任何更改。甚至連android:textOff和android:textOn都沒有任何效果。

我發現瞭如何自定義Android的切換視圖樣式一個偉大的職位,並通過所有的代碼看了,但找不到任何東西我做錯了: http://custom-android-dn.blogspot.co.uk/2013/01/how-to-use-and-custom-switch-in-android.html

真的不知道什麼嘗試。

下面是XML代碼:

<Switch 
     android:id="@+id/home_availability_switch" 
     style="@style/MySwitch" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" 
     android:enabled="true" 
     android:focusable="true" 
     android:textOff="Free" 
     android:textOn="Busy" /> 

這裏的風格:

<style name="MySwitch" parent="@style/Holo.Switch.Light"> 
    <item name="android:thumb">@drawable/selector_availability_switch_thumb</item> 
    <item name="android:track">@drawable/selector_availability_switch_background</item> 
</style> 

這裏是拇指選擇 (這些都是默認的系統可繪製我曾嘗試用不同的可繪製資源。):

<item android:drawable="@drawable/switch_thumb_pressed_holo_light" android:state_pressed="true"/> 
<item android:drawable="@drawable/switch_thumb_activated_holo_light" android:state_checked="true"/> 
<item android:drawable="@drawable/switch_thumb_disabled_holo_light" android:state_enabled="false"/> 
<item android:drawable="@drawable/switch_thumb_holo_dark"/> 

這裏是軌道選擇器 (這些是默認的系統可繪製。我有不同的可繪製試過):

<item android:drawable="@drawable/switch_bg_disabled_holo_dark" android:state_enabled="false"/> 
<item android:drawable="@drawable/switch_bg_focused_holo_dark" android:state_focused="true"/> 
<item android:drawable="@drawable/switch_bg_holo_dark"/> 

我也發現了這個帖子How can I style an Android Switch?,並按照指示,但沒有運氣。

其他人在使用Holo Everywhere時有類似的經歷?

回答

2

您需要像這樣定義開關。需要整個軟件包名稱才能工作。

<org.holoeverywhere.widget.Switch 
    android:id="@+id/lockSwitch" 
    style="?switchStyleOld" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="TestSwitch" /> 

希望這會有所幫助。

+0

您忘記爲「樣式」屬性添加名稱空間。 – 2013-05-10 13:19:28

+0

你不需要它的風格。 – 2013-05-10 13:32:06

+0

就是這樣!謝謝!花了整整一個早上messin與此。如上所述在holoeverywhere軟件包中引用Switch視圖類時,可修改屬性的前綴會更改爲app :.所以應用程序:textOn,應用程序:拇指等... – speedynomads 2013-05-10 13:53:21