Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom Drawable for ProgressBar/ProgressDialog
    text
    copied!<p>Reading the limited documentation that Google has provided, I get the feeling that it is possible to change the look (drawable) of a ProgressBar/ProgressDialog by simply creating a new style an assigning it to the style property of the ProgressBar. But I cannot get this to work properly. Here is what I did so far:</p> <p>I created a shape like this (mp2.xml)</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="ring" android:innerRadiusRatio="4" android:thicknessRatio="4" android:useLevel="false"&gt; &lt;size android:width="50dip" android:height="50dip" /&gt; &lt;gradient android:type="sweep" android:useLevel="false" android:startColor="#300000ff" android:centerColor="#500000ff" android:endColor="#ff0000ff" /&gt; &lt;/shape&gt; </code></pre> <p>then created an animation (mp3.xml) like this:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"&gt; &lt;item android:duration="70"&gt; &lt;rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/mp2" android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0" android:toDegrees="30" android:repeatCount="1" /&gt; &lt;/item&gt; &lt;item android:duration="70"&gt; &lt;rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/mp2" android:pivotX="50%" android:pivotY="50%" android:fromDegrees="30" android:toDegrees="60" android:repeatCount="1" /&gt; &lt;/item&gt; &lt;item android:duration="70"&gt; &lt;rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/mp2" android:pivotX="50%" android:pivotY="50%" android:fromDegrees="60" android:toDegrees="90" android:repeatCount="1" /&gt; &lt;/item&gt; &lt;item android:duration="70"&gt; &lt;rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/mp2" android:pivotX="50%" android:pivotY="50%" android:fromDegrees="90" android:toDegrees="120" android:repeatCount="1" /&gt; &lt;/item&gt; &lt;item android:duration="70"&gt; &lt;rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/mp2" android:pivotX="50%" android:pivotY="50%" android:fromDegrees="120" android:toDegrees="150" android:repeatCount="1" /&gt; &lt;/item&gt; &lt;item android:duration="70"&gt; &lt;rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/mp2" android:pivotX="50%" android:pivotY="50%" android:fromDegrees="150" android:toDegrees="180" android:repeatCount="1" /&gt; &lt;/item&gt; &lt;item android:duration="70"&gt; &lt;rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/mp2" android:pivotX="50%" android:pivotY="50%" android:fromDegrees="180" android:toDegrees="210" android:repeatCount="1" /&gt; &lt;/item&gt; &lt;item android:duration="70"&gt; &lt;rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/mp2" android:pivotX="50%" android:pivotY="50%" android:fromDegrees="210" android:toDegrees="240" android:repeatCount="1" /&gt; &lt;/item&gt; &lt;item android:duration="70"&gt; &lt;rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/mp2" android:pivotX="50%" android:pivotY="50%" android:fromDegrees="240" android:toDegrees="270" android:repeatCount="1" /&gt; &lt;/item&gt; &lt;item android:duration="70"&gt; &lt;rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/mp2" android:pivotX="50%" android:pivotY="50%" android:fromDegrees="270" android:toDegrees="300" android:repeatCount="1" /&gt; &lt;/item&gt; &lt;item android:duration="70"&gt; &lt;rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/mp2" android:pivotX="50%" android:pivotY="50%" android:fromDegrees="300" android:toDegrees="330" android:repeatCount="1" /&gt; &lt;/item&gt; &lt;item android:duration="70"&gt; &lt;rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/mp2" android:pivotX="50%" android:pivotY="50%" android:fromDegrees="330" android:toDegrees="360" android:repeatCount="1" /&gt; &lt;/item&gt; &lt;/animation-list&gt; </code></pre> <p>then created a style (attrs.xml) like this:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;style parent="@android:style/Widget.ProgressBar" name="customProgressBar"&gt; &lt;item name="android:progressDrawable"&gt;@anim/mp3&lt;/item&gt; &lt;/style&gt; &lt;/resources&gt; </code></pre> <p>and the in my main.xml I have set the style like this:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:drawingCacheQuality="high"&gt; &lt;ProgressBar android:id="@+id/ProgressBar01" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/customProgressBar"/&gt; &lt;/LinearLayout&gt; </code></pre> <p>But it still shows the same drawable as before. What am I doing wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload