Androbean Studio
Androbean Studio

Reputation: 382

Android - Switch track not drawn when turned off

I am using android.widget.Switch in a part of my app. The problem is that the track is not drawn when its turned off.

I did a little bit of debugging and found that the track is in fact there but, is just a translucent white, and hence will not show up against my white background.

Please see the picture below. First is when its ON, Second is when its OFF, and Third is OFF which black background on parent.

What I am wondering is; is using 'Switch' really this tricky? or am I missing something? I prefer not to use any custom drawable for track or the thumb.

UPDATE: I see that this is happening since I am using android:Theme.DeviceDefault.Wallpaper.NoTitleBar as my theme. If I use android:Theme.DeviceDefault.Light, there is no such issue. But unfortunately I need to stick with first theme. Can anybody tell me how can I customize android:Theme.DeviceDefault.Wallpaper.NoTitleBar so that I can probably solve this issue?

First is when its ON, Second is when its OFF, and Third is OFF with black background on parent.

Upvotes: 2

Views: 1496

Answers (1)

Androbean Studio
Androbean Studio

Reputation: 382

After another round of research I am able to finally do it. Posting here for my own and possibly others' reference.

It turns out that theme in fact can be customized at view level using the android:theme property.

So, in my case, all that I had to do was to add android:theme="@style/AppThemeSettings" to the Switch in the xml. AppThemeSettings is extending from android:Theme.DeviceDefault.Light and everything is good now.

Upvotes: 4

Related Questions