Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Honeycomb CheckBox against white background cannot be seen

I am putting a CheckBox against a white background. It looks fine on pre-Honeycomb devices but on Honeycomb, it seems that the graphic has partial transparency and is white, so when the checkbox is unticked, you cannot see it.

I tried using the Theme.Holo.Light style as follows:

<CheckBox android:text="" style="@android:style/Theme.Holo.Light"
android:layout_marginLeft="5dip" android:id="@+id/checkBoxWifiOnly" 
android:layout_width="wrap_content" android:layout_height="wrap_content" />

This appears to have no effect. Am I typing the syntax wrongly?

like image 792
albnok Avatar asked Nov 04 '22 14:11

albnok


1 Answers

You are applying the theme in a wrong way. Either apply @android:style/Theme.Holo.Light to the whole app/activity in the AndroidManifest.xml, or use @android:style/Widget.Holo.Light.CompoundButton.CheckBox as the style of your CheckBox. Also note that the "Holo" theme is available only on Honeycomb and higher.

I think that you'll have to apply the theme to the whole app, if you want the checkbox to have a different background. The thing is, that Widget.Holo.Light.CompoundButton.CheckBox and Widget.Holo.CompoundButton.CheckBox are the same and both extend the Widget.CompoundButton.CheckBox style, which has the "button" variable set by the theme attribute listChoiceIndicatorMultiple. This attribute's value is, in fact, different for light and dark theme.

I'd suggest you to create your own theme in values/themes.xml file, like this:

<style name="Theme.MyAwesomeApp" parent="@android:style/Theme.Light">
...
</style>

and in values-v11/themes.xml, like this:

<style name="Theme.MyAwesomeApp" parent="@android:style/Theme.Holo.Light">
...
</style>

and then set it in your AndroidManifest.xml, like this:

<application android:theme="@style/Theme.MyAwesomeApp" ... >
...
</application>

Maybe you should also read how the themes and styles work: https://developer.android.com/guide/topics/ui/themes.html

like image 107
cermak.cz Avatar answered Nov 09 '22 04:11

cermak.cz