我有以下评级栏:
final RatingBar rating = new RatingBar(mContext);
rating.setStepSize(1);
rating.setMax(5);
}
现在我想更改API 14的ratingbar颜色。
我写了以下代码:
rating.setProgressTintList(mContext.getResources().getColorStateList(R.color.colorAccent));
但这适用于上述API 21。
我想为API 14设置此颜色。
我该怎么做?
答案 0 :(得分:0)
您可以使用此网站从此
创建颜色相关的小部件http://android-holo-colors.com/
为Ratting或任何其他想要更改内容的小部件制作自己的风格。像这样...
<style name="MyRatting" parent="android:Widget.Holo.Light.RatingBar">
<item name="android:background">@drawable/apptheme_spinner_background_holo_light</item>
..... keep changing desired items
</style>
之后将此样式应用于应用程序引用的主样式
<style name="AppThemeTest" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:ratingBarStyle">@style/MyRatting</item>
</style>
某个时候应用程序可能无法为相应Widget
的应用程序选择您给定的样式,在这种情况下直接将样式应用于此类Widget
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/MyRatting"
android:id="@+id/ratingBar" />