Android Drawable support issue (Progress Bar, Switch)

I am trying to implement the below interface. I am using Eclipse with ADT plugin.

Spotify UI

Below is the implementation of circle [White + Dark Gray] (circle_shape.xml):

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background">
        <shape android:shape="ring" android:innerRadius="65dp" android:thickness="10dp"
            android:useLevel="false">
            <solid android:color="@android:color/white" />
        </shape>
    </item>
    <item android:id="@android:id/progress">
        <shape android:shape="ring" android:innerRadius="57dp" android:thickness="8dp" android:useLevel="false">
            <solid android:color="#FF393939" />
        </shape>
    </item>
</layer-list>

      

and a progress bar [Green] (circle_progress_bar.xml) like:

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="270" android:toDegrees="270">
    <shape android:innerRadius="65dp" android:shape="ring" android:thickness="10dp">
        <gradient android:angle="0" android:endColor="#FF00FF00" android:startColor="#FF00FF00" android:type="sweep" android:useLevel="false" />
    </shape>
</rotate>

      

In the layout XML file:

<ProgressBar
    android:id="@+id/progressBar"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:layout_alignBottom="@+id/repeat"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="36dp"
    android:background="@drawable/circle_shape"
    android:indeterminate="false"
    android:max="100"
    android:progress="65"
    android:progressDrawable="@drawable/circular_progress_bar" />

      

Problem 1:          The above code gives me the exact shape I want, but only with API 19 and API 20. As soon as I switch the preview mode in Eclipse to API 21, progressDrawable seems to fill a full circle, leaving only one circle filled with green. I cannot figure out how to do the same on Android L.

Problem 2:         It has to do with the radio buttons. In API 21, I can easily install

<android:textOn="" android:textOff="">

      

and the buttons look ok. However, if I examine this in API19, then the Thumb drawable will be garbled (compressed) until I set some text using the textOn and textOff attributes.

Can someone please help me with the same?

Please feel free to move / close the question if it doesn't seem constructive enough. But please be kind enough to redirect me to another useful resource.

Edit 1 : Below is a screenshot for Issue 2 API 19 and API 21 Comparison

The XML switch for the switch looks like this:

<Switch
        android:id="@+id/switch1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/repeat"
        android:layout_alignBottom="@+id/repeat"
        android:layout_alignParentLeft="true"
        android:background="@drawable/toogle_selector"
        android:checked="true"
        android:thumb="@drawable/circle_1"
        android:track="@drawable/transparent"
        android:textOn=""
        android:textOff=""/>

      

+3


source to share


1 answer


Found a solution to your problem

in "Circular_progress_bar"

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="270"
    android:toDegrees="270" >

    <shape
        android:innerRadius="65dp"
        android:shape="ring"
        android:thickness="10dp"
        android:useLevel="true" >
        <gradient
            android:angle="0"
            android:endColor="#FF00FF00"
            android:startColor="#FF00FF00"
            android:type="sweep"
            android:useLevel="false" />
    </shape>

</rotate>

      



Since android: useLevel = "true" defaults to false is API level 21

Before enter image description here

After enter image description here

+8


source







All Articles