如何加载方式运行的的RatingBar的Android [英] How to load Style Runtime for Ratingbar Android
问题描述
我有一个片段Feedback.java。有一个按钮这就引起一个popupwindow。我创建在弹出的窗口一个等级吧。我的自定义样式评级的酒吧在XML文件中定义的。我定义的风格值/ styles.xml
I have a fragment Feedback.java. there is a button which raises a popupwindow. I am creating a Rating bar in popup Window. My Custom Style for Rating bar is defined in XML files. i defined Style in values/styles.xml
<style name="RatingBar1" parent="@android:style/Widget.RatingBar">
<item name="android:progressDrawable">@drawable/rating_bar_full</item>
<item name="android:minHeight">48dip</item>
<item name="android:maxHeight">48dip</item>
</style>
我创建的RatingBar运行时使用下面的code以上的风格。
I have created RatingBar runtime with above style using following code.
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
param.setMarginStart(15);
float stepSize = (float) 0.5;
rating = new RatingBar(getActivity(), null,R.style.RatingBar1);
rating.setNumStars(5);
rating.setStepSize(stepSize);
但评分栏没有显示。我知道这是一个样式加载的onCreate(有问题),我们craete弹出的ButtonClick。这就是为什么风格不适用。所以,我怎么可以加载方式在运行时为我的RatingBar。任何建议。感谢名单到了!
but Rating bar is not showing. I know this is a problem that Styles are loaded onCreate() and we craete popup on ButtonClick. that is why Style is not applying. So how can i load Style at runtime for my RatingBar. Any Suggestion. Thanx Already!
推荐答案
这为我工作。您可以设置任何颜色上运行时RatingBr明星。试试这个。
this worked for me. you can set any color to stars on runtime for RatingBr. Try this.
rbCustom = new RatingBar(getActivity());
rbCustom.setNumStars(5);
rbCustom.setStepSize(stepSize);
LayerDrawable stars = (LayerDrawable) rbCustom.getProgressDrawable();
stars.getDrawable(2).setColorFilter(getResources().getColor(R.color.oceanBlue),Mode.SRC_ATOP);
这篇关于如何加载方式运行的的RatingBar的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!