English 中文(简体)
检查Box 按钮选择器导致隐形复选框
原标题:CheckBox button selector results in invisble checkbox

我试图在我的布局中 使用复式字节元素的样式 。

由于我想要不同活动的风格一致, 我创造了一个自定义的主题, 我应用在货单上。

样式. 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\\\\\\\\\\\\\\\\\\\\\\\dpi} dpi 文件夹中 。

奇怪的是,这在很长一段时间里非常有效。 但是今天, 它突然停止工作了。 复选框元素现在出现了, 没有框块。 只有文本是可见的 。

所有其他自定义的自定义元素都按原意工作, 而 CheckBox 则显示这种奇怪的行为 。

我试图直接将该样式应用到 xml 的复选框中, 没有运气 。 也做了通常的清理工程 。 我唯一能让它工作的办法是将选择器复制到我工程中的所有可绘制文件夹 {l\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\所有可绘制文件夹。 我感到没有必要在每个可绘制的文件夹中都有选择器,,, 并且肯定不需要我的其他自定义的其他自定义选择器。

有人能发现我的代码有明显缺陷吗?

最佳回答

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

从 btn_ check_ selector.xml 重新命名我的选择器, 重命名为 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\\\\\\\\\\\\\\\\\\\\\\\\\\\\dpi} 。

这有点奇怪,因为在我的项目中,我没有任何叫 Btn_ check_selector 的其他文件。我唯一的猜测是, Eclipse 行动了!

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签