开发者

Problem in implementing Android rating bar style

开发者 https://www.devze.com 2023-03-20 17:07 出处:网络
I want to make style for rating bar programmatically. I\'ve read this tutorial Pretty Rating Bar I can do layerList and selector and I can link them programmatically b开发者_JAVA技巧ut I can\'t link

I want to make style for rating bar programmatically. I've read this tutorial Pretty Rating Bar

I can do layerList and selector and I can link them programmatically b开发者_JAVA技巧ut 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 RatingBar rb=new RatingBar(getBaseContext(), null, defStyle);.

to make custom rating bar I need to do the following :-

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:

    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));

this for fullEmpty:-

        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));

2-then I should make layerList of those drawables I've made like this:-

Drawable[] d=new LayerDrawable[2];

    d[0]=state_fullEmpty;
    d[1]=state_fullFilled;
    LayerDrawable layer=new LayerDrawable(d);

3-I should make this step programmatically But I can't:-

<style name="foodRatingBar" parent="@android:style/Widget.RatingBar">
    <item name="android:progressDrawable">@drawable/food_ratingbar_full</item>
0

精彩评论

暂无评论...
验证码 换一张
取 消