Android:将等级栏的颜色更改为金色 [英] Android: Change color of ratingbar to golden

查看:142
本文介绍了Android:将等级栏的颜色更改为金色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将等级栏的颜色更改为金色.
我不想自定义星星,我只想更改API 16或更高版本的颜色
我尝试了以下解决方案,但没有一个对我有用

I want to change color of rating bar to golden.
I dont want to customize the stars, i just want to change the color for API 16 or above
I have tried following solutions but none of them worked out for me

1.    

RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar);
LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable();
stars.getDrawable(2).setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);

2.

android:progressDrawable="@color/golden" in XML

推荐答案

此选项现在包含在AppCompat库中.自动使用RatingBar的AppCompat版本.

This option is now included in the AppCompat library. The AppCompat version of the RatingBar is used automatically.

http://developer.android.com/reference/android/support/v7/widget/AppCompatRatingBar.html

示例(来自我自己的应用):

Example (from my own app):

<RatingBar
    android:id="@+id/rating"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:numStars="5"
    android:stepSize="1"
    android:theme="@style/RatingBar"/>

带有主题:

<style name="RatingBar" parent="Theme.AppCompat">
    <item name="colorControlNormal">@color/duskYellow</item>
    <item name="colorControlActivated">@color/lightGrey</item>
</style>

这篇关于Android:将等级栏的颜色更改为金色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆