अनुरूप आकार स्विच काम नहीं कर रहा है कि जैसा दिखता है:कस्टम स्विच - ट्रैक और चयनकर्ता आकार के नीचे 21 एपीआई
एपीआई से ऊपर 21
एपीआई 21नीचे
लगता है कि <size/>
ब्लॉक पूर्व 21 एपीआई के लिए <shape/>
में काम नहीं करता है।
कोई विचार यह कैसे हल करें?
कोड
container.xml:
<Switch
android:id="@id/switch_follow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:textOff=""
android:textOn=""
android:thumb="@drawable/switch_selector"
android:track="@drawable/switch_track"/>
drawable/switch_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item
android:bottom="@dimen/switch_selector_padding"
android:left="@dimen/switch_selector_padding"
android:right="@dimen/switch_selector_padding"
android:top="@dimen/switch_selector_padding">
<shape
android:dither="true"
android:shape="oval"
android:useLevel="false"
android:visible="true">
<gradient
android:angle="270"
android:endColor="@color/primary_white"
android:startColor="@color/primary_white"/>
<corners
android:radius="@dimen/switch_radius"/>
<size
android:width="@dimen/switch_track_height"
android:height="@dimen/switch_track_height" />
</shape>
</item>
</layer-list>
</item>
</selector>
drawable/switch_track.xml:
01,235,<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true"
android:shape="rectangle"
android:useLevel="false"
android:visible="true">
<gradient
android:angle="270"
android:endColor="@color/primary_yellow_dark_v2"
android:startColor="@color/primary_yellow_dark_v2"/>
<corners android:radius="@dimen/switch_radius" />
<stroke
android:width="@dimen/switch_stroke_height"
android:color="@android:color/transparent">
</stroke>
<size
android:width="@dimen/switch_track_width"
android:height="@dimen/switch_track_height" />
</shape>
शायद किसी को भी इसी तरह की समस्या का सामना करना पड़ा। कृपया अपना अनुभव साझा करें।
संपादित: जोड़ा dimens
<dimen name="switch_track_width">36dp</dimen>
<dimen name="switch_track_height">30dp</dimen>
<dimen name="switch_radius">50dp</dimen>
<dimen name="switch_selector_padding">2dp</dimen>
<dimen name="switch_stroke_height">0dp</dimen>
कृपया पोस्ट @ Dimen/switch_track_width और ऊंचाई आकार के लिए एक सही त्रिज्या परिभाषा के आधे व्यास का एक
thumbTextPadding
जोड़ सकते हैं और । – Warpzit@Warpzit, कृपया मेरा संपादन – AnZ
देखें मुझे लगता है (लेकिन सुनिश्चित नहीं है) कि XML टैग यहां गलत है। सिवाय इसके कि यह एक एक्सएमएल सिंटैक्स त्रुटि के कारण होता है (जो ऐसा नहीं लगता है, विशेष रूप से यदि पिछले संस्करणों में काम किया गया है, लेकिन यह असंभव नहीं है ...) xml डेटा फ़ाइलों के लिए प्रारूप उपयोगकर्ता होता है जैसे कि सादे पाठ या ".ini" बिना किसी सवाल के प्रारूप में इस्तेमाल किया गया प्रारूप, वास्तव में, इसके साथ कुछ लेना देना नहीं है। – bitifet