复选框按钮选择器导致不可见的复选框



我正在尝试设置我在布局中使用的复选框元素的样式。

由于我希望样式在不同活动中保持一致,因此我创建了一个自定义主题,并在清单中应用。

样式.xml文件如下所示:

<style name="LightTheme" parent="@android:style/Theme.NoTitleBar">
   .
   .
   <item name="android:checkboxStyle">@style/CustomCheckBox</item>
   .
   .
</style>
.
.
<style name="CustomCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox"> 
    <item name="android:button">@drawable/btn_check_selector</item> 
    <item name="android:textColor">@color/mainTextColorLight</item>
    <item name="android:textSize">15dp</item>
</style> 
.
.

选择器与 SDK 中的复选框选择器基本相同,如下所示:

<!-- Enabled states -->        
<item android:state_checked="true" android:state_window_focused="false"
      android:state_enabled="true"
      android:drawable="@drawable/btn_check_on" />
<item android:state_checked="false" android:state_window_focused="false"
      android:state_enabled="true"
      android:drawable="@drawable/btn_check_off" />
<item android:state_checked="true" android:state_pressed="true"
      android:state_enabled="true"
      android:drawable="@drawable/btn_check_on_pressed" />
<item android:state_checked="false" android:state_pressed="true"
      android:state_enabled="true"
      android:drawable="@drawable/btn_check_off_pressed" />
<item android:state_checked="true" android:state_focused="true"
      android:state_enabled="true"
      android:drawable="@drawable/btn_check_on_focused" />
<item android:state_checked="false" android:state_focused="true"
      android:state_enabled="true"
      android:drawable="@drawable/btn_check_off_focused" />
<item android:state_checked="false"
      android:state_enabled="true"
      android:drawable="@drawable/btn_check_off" />
<item android:state_checked="true"
      android:state_enabled="true"
      android:drawable="@drawable/btn_check_on" />

<!-- Disabled states -->
<item android:state_checked="true" android:state_window_focused="false"
      android:drawable="@drawable/btn_check_on_disabled" />
<item android:state_checked="false" android:state_window_focused="false"
      android:drawable="@drawable/btn_check_off_disabled" />
<item android:state_checked="true" android:state_focused="true"
      android:drawable="@drawable/btn_check_on_disabled_focused" />
<item android:state_checked="false" android:state_focused="true"
      android:drawable="@drawable/btn_check_off_disabled_focused" />
<item android:state_checked="false" android:drawable="@drawable/btn_check_off_disabled" />
<item android:state_checked="true" android:drawable="@drawable/btn_check_on_disabled" />

选择器存储在我的项目的"可绘制"文件夹中,密度特定的资源存储在可绘制的 {l|m|h|xh}dpi 文件夹中。

奇怪的是,这在很长一段时间内都运作良好。但是今天,它突然不再起作用了。复选框元素现在显示时没有框部分。只有文本可见。

所有其他自定义样式元素都按预期工作,而复选框显示这种奇怪的行为。

我尝试将样式直接应用于带有xml的复选框,但没有运气。还完成了通常的"清洁项目"。我能让它工作的唯一方法是将选择器复制到我项目中的所有可绘制对象 {l|m|h|xh}dpi 文件夹中。我的印象是,没有必要在每个可绘制文件夹中都有选择器的副本,对于我的其他自定义选择器来说当然也没有必要。

任何人都可以在我的代码中发现任何明显的缺陷吗?

终于解决了,问题似乎是某种名称冲突。

将我的选择器从"btn_check_selector.xml"重命名为"selector_check.xml",并对我的自定义复选框样式进行了相应的更改:

<style name="CustomCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox"> 
    <item name="android:button">@drawable/selector_check</item> 
    <item name="android:textColor">@color/mainTextColorLight</item>
    <item name="android:textSize">15dp</item>
</style> 

选择器位于我的项目的"可绘制"文件夹中,密度特定的资源位于它们各自的可绘制对象 {l|m|h|xh}dpi 文件夹中。

这有点奇怪,因为我在项目中的任何地方都没有任何其他名为"btn_check_selector"的文件。我唯一的猜测是Eclipse正在行动!

最新更新