niestandardowej przełącznik kształt wygląda tak:klienta Switch - tor i wielkość selektor nie działa poniżej 21 API
Przede API 21
Poniżej API 21
Wydaje się, że blok <size/>
nie działa w <shape/>
dla API 21 pre.
Wszelkie pomysły, jak rozwiązać ten problem?
KOD
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"/>
odkształcalne/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>
odkształcalne/switch_track.xml:
<?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>
Być może ktoś borykał się z podobnym problemem. Podziel się wrażeniami.
EDIT: dodano dimens wykorzystywane
<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>
proszę umieszczać @ Dimen/switch_track_width i wysokość rozmiarach . – Warpzit
@Warpzit, sprawdź moją edycję – AnZ
Myślę (ale nie jestem pewien), że tag XML jest tutaj nieprawidłowy. Z wyjątkiem sytuacji, gdy jest to spowodowane błędem składni xml (co wydaje się nie być, szczególnie jeśli działało w poprzednich wersjach, ale nie jest niemożliwe ...) xml okazuje się być formatem użytkownika dla plików danych tak samo jak zwykły tekst lub ".ini" jest format użyty w zbyt wielu pytaniach, nie mając w rzeczywistości nic z tym wspólnego. – bitifet