Android Widget for Android: Android setup: Tracking makes the thumb and track not appear

I'm having trouble adjusting the look of the Android Switch widget. I have custom xml drawings that I want to use for the thumb (the small part of the button that usually says โ€œOnโ€ or โ€œOffโ€), And the track (the background on which the slide is a slide). When I install only the thumb using android: thumb, it works fine. When I set the track (regardless of whether the thumb is set), the switch completely disappears, and I just have the text.

Here is my code when only the thumb is applied:

<com.blahblahblah.blah.CustomSwitch android:id="@+id/switch_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textOff="Off" android:textOn="On" android:text="Something Awesome" android:textColor="@android:color/black" android:thumb="@drawable/custom_switch_thumb" /> 

Here's what it looks like in the preview window:

enter image description here

And with the track used:

 <com.blahblahblah.blah.CustomSwitch android:id="@+id/switch_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textOff="Off" android:textOn="On" android:text="Something Awesome" android:textColor="@android:color/black" android:track="@color/track_color" /> 

Preview window with track used:

enter image description here

For reference, I am using Android Studio 0.2.3 on OSX 10.7.5.

+6
source share
2 answers

I just stumbled upon the same issue and found a fix in HoloEverywhere's Problem Tracking . You need to set the <size> extractable XML form that you are using.

It doesnโ€™t work (there is a widget, and I can interact with it, but I donโ€™t see it, it is hidden):

 <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@color/black_50" /> </shape> 

Work (not added by <size> ):

 <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@color/black_50" /> <size android:width="56dp" android:height="20dp" /> </shape> 
+20
source

In general, just to change the image you do not need to subclass the control, which you can style it, for example. with style attribute.

There are several controls about your problem that expect drawing, not simple color. In the control definition (the xml part), you can simply determine that you allow the link, but you cannot limit it to the available links. So just avoid using colors directly. If you do not want to add an image, you can also define it using xml, but note that this does not work in all cases.

0
source

Source: https://habr.com/ru/post/953324/


All Articles