Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem in implementing Android rating bar style
    primarykey
    data
    text
    <p>I want to make style for rating bar programmatically. I've read this tutorial <a href="http://kozyr.zydako.net/2010/05/23/pretty-ratingbar/" rel="nofollow">Pretty Rating Bar</a></p> <p>I can do layerList and selector and I can link them programmatically but I can't link the layerList I made with The style attribute programmatically so I can set the style attribute in the rating bar constructor with my own style <code>RatingBar rb=new RatingBar(getBaseContext(), null, defStyle);</code>.</p> <p>to make custom rating bar I need to do the following :-</p> <p>1-make 2 xmls one for the full_empty state and another one for full empty they both include selectors I made this for example for the fullFilled state:</p> <pre><code> StateListDrawable state_fullFilled = new StateListDrawable(); state_fullFilled.addState(new int[] {android.R.attr.state_pressed}, getResources().getDrawable(R.drawable.star_rated)); state_fullFilled.addState(new int[] {android.R.attr.state_focused}, getResources().getDrawable(R.drawable.star_rated)); state_fullFilled.addState(new int[] {android.R.attr.state_selected }, getResources().getDrawable(R.drawable.star_rated)); </code></pre> <p>this for fullEmpty:-</p> <pre><code> StateListDrawable state_fullEmpty = new StateListDrawable(); state_fullEmpty.addState(new int[] {android.R.attr.state_pressed}, getResources().getDrawable(R.drawable.rate)); state_fullEmpty.addState(new int[] {android.R.attr.state_focused}, getResources().getDrawable(R.drawable.rate)); state_fullEmpty.addState(new int[] { android.R.attr.state_selected}, getResources().getDrawable(R.drawable.rate)); </code></pre> <p>2-then I should make layerList of those drawables I've made like this:-</p> <pre><code>Drawable[] d=new LayerDrawable[2]; d[0]=state_fullEmpty; d[1]=state_fullFilled; LayerDrawable layer=new LayerDrawable(d); </code></pre> <p>3-I should make this step programmatically But I can't:-</p> <pre><code>&lt;style name="foodRatingBar" parent="@android:style/Widget.RatingBar"&gt; &lt;item name="android:progressDrawable"&gt;@drawable/food_ratingbar_full&lt;/item&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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