2013-05-10 156 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