我可以为评级栏创建自定义图标,但我想以编程方式在不同情况下添加不同的评级栏。
有没有办法实现这个而不是在xml文件中初始化?
答案 0 :(得分:0)
我有一个解决方案
ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(context, R.style.ProfileRatingBar);
RatingBar rate = new RatingBar(contextThemeWrapper, null, 0);
R.style.ProfileRatingBar
是我的自定义评级栏。代码
<style name="ProfileRatingBar" parent="@android:style/Widget.RatingBar">
<item name="android:progressDrawable">@drawable/profile_ratingbar</item>
<item name="android:minHeight">24dp</item>
<item name="android:maxHeight">24dp</item>
</style>
希望这会对你有所帮助。