开发者

How to set ratingbar style from programmatically?

开发者 https://www.devze.com 2022-12-22 23:55 出处:网络
I don\'t see any method like set开发者_运维百科Style for class RatingBar. How can I set the rating style from code?This works for me (source):

I don't see any method like set开发者_运维百科Style for class RatingBar. How can I set the rating style from code?


This works for me (source):

RatingBar rating =
  new RatingBar(context, null, android.R.attr.ratingBarStyleSmall);


You need to set it in xml file! If you like to change it on the run, you can have two different View-s (rb) and switch them in the program (add/remove from layout) or use rb1.setVisibility(View.VISIBLE) and rb2.setVisibility(View.GONE);

<RatingBar 
    android:layout_height="wrap_content" android:layout_width="wrap_content"
    android:layout_alignParentRight="true" android:id="@+id/rb1"
    style="?android:attr/ratingBarStyleSmall"
    android:clickable="false" android:numStars="5">
</RatingBar>


If you are programmatically creating the RatingBar as follows the

RatingBar rating = new RatingBar(context, null, android.R.attr.ratingBarStyleSmall);

then don't for get to add

rating.setIsIndicator(false);

else the touch will not work on RatingBar.

The android.R.attr.ratingBarStyleSmall gives you very small stars if you want to have a slightly bigger stars use android.R.attr.ratingBarStyleIndicator

0

精彩评论

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