如何以编程方式设置评级栏样式?
我没有看到任何类似于RatingBar 类的setStyle 的方法。如何从代码中设置评分样式?
I don't see any method like setStyle for class RatingBar. How can I set the rating style from code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这对我有用(来源):
This works for me (source):
你需要在xml文件中设置它!如果您想在运行时更改它,您可以有两个不同的 View-s (rb) 并在程序中切换它们(从布局中添加/删除)或使用 rb1.setVisibility(View.VISIBLE) 和 rb2.setVisibility(View .消失);
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,如下所示
RatingBar rating = new RatingBar(context, null, android.R.attr. ratingBarStyleSmall);
那么不要添加
rating.setIsIndicator (false);
否则触摸将无法在RatingBar 上运行。
如果您想要稍大的星星,则使用
android.R.attr. ratingBarStyleIndicator
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 useandroid.R.attr.ratingBarStyleIndicator