Android: Change color of ratingbar to golden
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
android ratingbar
add a comment |
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
android ratingbar
does it mean changing the color of stars?
– Rahul Tiwari
Sep 27 '15 at 17:27
yes............................................
– ojas
Sep 27 '15 at 17:37
4
possible duplicate of Android RatingBar change star colors
– Rahul Tiwari
Sep 27 '15 at 17:46
add a comment |
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
android ratingbar
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
android ratingbar
android ratingbar
asked Sep 27 '15 at 16:46
ojasojas
70021230
70021230
does it mean changing the color of stars?
– Rahul Tiwari
Sep 27 '15 at 17:27
yes............................................
– ojas
Sep 27 '15 at 17:37
4
possible duplicate of Android RatingBar change star colors
– Rahul Tiwari
Sep 27 '15 at 17:46
add a comment |
does it mean changing the color of stars?
– Rahul Tiwari
Sep 27 '15 at 17:27
yes............................................
– ojas
Sep 27 '15 at 17:37
4
possible duplicate of Android RatingBar change star colors
– Rahul Tiwari
Sep 27 '15 at 17:46
does it mean changing the color of stars?
– Rahul Tiwari
Sep 27 '15 at 17:27
does it mean changing the color of stars?
– Rahul Tiwari
Sep 27 '15 at 17:27
yes............................................
– ojas
Sep 27 '15 at 17:37
yes............................................
– ojas
Sep 27 '15 at 17:37
4
4
possible duplicate of Android RatingBar change star colors
– Rahul Tiwari
Sep 27 '15 at 17:46
possible duplicate of Android RatingBar change star colors
– Rahul Tiwari
Sep 27 '15 at 17:46
add a comment |
10 Answers
10
active
oldest
votes
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"/>
With theme:
<style name="RatingBar" parent="Theme.AppCompat">
<item name="colorControlNormal">@color/duskYellow</item>
<item name="colorControlActivated">@color/lightGrey</item>
</style>
4
Along with the above answer, use style="@style/Base.Widget.AppCompat.RatingBar.Small" or @style/Base.Widget.AppCompat.RatingBar.Indicator in the rating bar widget to play around with the colour of the rating star and the size as well.
– godslayer_69
Apr 25 '16 at 17:47
19
Doesn't work for Pre-lolipop.
– Malder
May 20 '16 at 7:47
1
is there any way to do this programmatically? i need to change star colour at runtime
– Євген Гарастович
Jan 10 '17 at 12:31
2
nevermind. found this awesome lib here: github.com/FlyingPumba/SimpleRatingBar we should give this man a medal. customizability is over the rooftop
– Євген Гарастович
Jan 11 '17 at 9:25
1
It is also working fine on KitKat.
– Parth Patel
Oct 25 '18 at 13:16
|
show 2 more comments
Simply add this line to xml
(API 21 and higher)
android:progressTint="@color/color"
add a comment |
As you mentioned that you want to change the star color without using the drawable. You can do it by few lines of code as below.
RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar);
Drawable drawable = ratingBar.getProgressDrawable();
drawable.setColorFilter(Color.parseColor("#0064A8"),PorterDuff.Mode.SRC_ATOP);
5
It draws 5 colored stars, not 3.5, for instance.
– CoolMind
Mar 16 '16 at 13:55
add a comment |
My task was change color of Rating Bar to the app's primary color for Android >=14 SDK. I've solved this problem in code and in xml file.
mRatingBar = (RatingBar)view.findViewById(R.id.ratingBar);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
try {
Drawable progressDrawable = mRatingBar.getProgressDrawable();
if (progressDrawable != null) {
DrawableCompat.setTint(progressDrawable, ContextCompat.getColor(getContext(), R.color.colorPrimary));
}
} catch (Exception e) {
e.printStackTrace();
}
}
And in xml file
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:backgroundTint="@color/colorPrimary"
android:numStars="5"
android:progressTint="@color/colorPrimary"
android:rating="0"
android:secondaryProgressTint="@android:color/transparent"
android:stepSize="1" />
add a comment |
try this,
You do need 3 star images (red_star_full.png, red_star_half.png and red_star_empty.png) and one xml file. If you want to golden star then use golden star image. this is for red star.
you can put ratingbar_color.xml in res/drawable.
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background" android:drawable="@drawable/red_star_empty" />
<item android:id="@android:id/secondaryProgress" android:drawable="@drawable/red_star_half" />
<item android:id="@android:id/progress" android:drawable="@drawable/red_star_full" />
</layer-list>
and in rating bar definition use following.
<RatingBar android:progressDrawable="@drawable/ratingbar_red/>
2
Duplicate of stackoverflow.com/questions/2446270/…
– turbandroid
Dec 25 '15 at 17:37
add a comment |
RatingBar ratingreview;
ratingreview=(RatingBar)v.findViewById(R.id.ratingreview);
ratingreview.setRating(Float.parseFloat(objrating));
Drawable drawable = ratingreview.getProgressDrawable();
drawable.setColorFilter(Color.parseColor("#6A9A28"), PorterDuff.Mode.SRC_ATOP);
add a comment |
My use case was to show different colors for different ratings. For example :
1- Red
2- Orange
3- Yellow
4- Light Green
5- Dark Green
Solution :
ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(final RatingBar ratingBar, final float rating, final boolean fromUser) {
setCurrentRating(rating);
}
});
Then in your setCurrentRating()
method :
private void setCurrentRating(float rating) {
LayerDrawable drawable = (LayerDrawable)rateOverall.getProgressDrawable();
if(mContext!=null) {
switch (Math.round(rating)) {
case 1:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.dark_red));
break;
case 2:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.light_orange));
break;
case 3:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.light_yellow));
break;
case 4:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.light_green_review));
break;
case 5:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.dark_green));
break;
}
setRatingStarColor(drawable.getDrawable(1), ContextCompat.getColor(mContext, R.color.transparent));
setRatingStarColor(drawable.getDrawable(0), ContextCompat.getColor(mContext, R.color.light_grey_payment));
}
}
Then in your setRatingStarColor()
method:
private void setRatingStarColor(Drawable drawable, @ColorInt int color)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
DrawableCompat.setTint(drawable, color);
}
else
{
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
}
Thanks to this answer which helped me solve this.
Hope it helps someone !
add a comment |
Use this code to get over the line
Drawable drawableReview = writeReviewRatingBar.getProgressDrawable();
drawableReview.setColorFilter(Color.parseColor("#FFFDD433"), PorterDuff.Mode.SRC_ATOP);
add a comment |
Simple solution, use AppCompatRatingBar and use below code
ratingbar.setProgressTintList(ColorStateList.valueOf(ContextCompat.getColor(context, R.color.colorAccent)));
add a comment |
The simplest solution I have found is changing the color definition for the color "colorAccent" in the color.xml. That's entire magic without further coding.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32810341%2fandroid-change-color-of-ratingbar-to-golden%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
10 Answers
10
active
oldest
votes
10 Answers
10
active
oldest
votes
active
oldest
votes
active
oldest
votes
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"/>
With theme:
<style name="RatingBar" parent="Theme.AppCompat">
<item name="colorControlNormal">@color/duskYellow</item>
<item name="colorControlActivated">@color/lightGrey</item>
</style>
4
Along with the above answer, use style="@style/Base.Widget.AppCompat.RatingBar.Small" or @style/Base.Widget.AppCompat.RatingBar.Indicator in the rating bar widget to play around with the colour of the rating star and the size as well.
– godslayer_69
Apr 25 '16 at 17:47
19
Doesn't work for Pre-lolipop.
– Malder
May 20 '16 at 7:47
1
is there any way to do this programmatically? i need to change star colour at runtime
– Євген Гарастович
Jan 10 '17 at 12:31
2
nevermind. found this awesome lib here: github.com/FlyingPumba/SimpleRatingBar we should give this man a medal. customizability is over the rooftop
– Євген Гарастович
Jan 11 '17 at 9:25
1
It is also working fine on KitKat.
– Parth Patel
Oct 25 '18 at 13:16
|
show 2 more comments
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"/>
With theme:
<style name="RatingBar" parent="Theme.AppCompat">
<item name="colorControlNormal">@color/duskYellow</item>
<item name="colorControlActivated">@color/lightGrey</item>
</style>
4
Along with the above answer, use style="@style/Base.Widget.AppCompat.RatingBar.Small" or @style/Base.Widget.AppCompat.RatingBar.Indicator in the rating bar widget to play around with the colour of the rating star and the size as well.
– godslayer_69
Apr 25 '16 at 17:47
19
Doesn't work for Pre-lolipop.
– Malder
May 20 '16 at 7:47
1
is there any way to do this programmatically? i need to change star colour at runtime
– Євген Гарастович
Jan 10 '17 at 12:31
2
nevermind. found this awesome lib here: github.com/FlyingPumba/SimpleRatingBar we should give this man a medal. customizability is over the rooftop
– Євген Гарастович
Jan 11 '17 at 9:25
1
It is also working fine on KitKat.
– Parth Patel
Oct 25 '18 at 13:16
|
show 2 more comments
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"/>
With theme:
<style name="RatingBar" parent="Theme.AppCompat">
<item name="colorControlNormal">@color/duskYellow</item>
<item name="colorControlActivated">@color/lightGrey</item>
</style>
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"/>
With theme:
<style name="RatingBar" parent="Theme.AppCompat">
<item name="colorControlNormal">@color/duskYellow</item>
<item name="colorControlActivated">@color/lightGrey</item>
</style>
edited Aug 2 '17 at 15:13
Barakat Turki
1541212
1541212
answered Mar 10 '16 at 11:03
theblitztheblitz
3,095104699
3,095104699
4
Along with the above answer, use style="@style/Base.Widget.AppCompat.RatingBar.Small" or @style/Base.Widget.AppCompat.RatingBar.Indicator in the rating bar widget to play around with the colour of the rating star and the size as well.
– godslayer_69
Apr 25 '16 at 17:47
19
Doesn't work for Pre-lolipop.
– Malder
May 20 '16 at 7:47
1
is there any way to do this programmatically? i need to change star colour at runtime
– Євген Гарастович
Jan 10 '17 at 12:31
2
nevermind. found this awesome lib here: github.com/FlyingPumba/SimpleRatingBar we should give this man a medal. customizability is over the rooftop
– Євген Гарастович
Jan 11 '17 at 9:25
1
It is also working fine on KitKat.
– Parth Patel
Oct 25 '18 at 13:16
|
show 2 more comments
4
Along with the above answer, use style="@style/Base.Widget.AppCompat.RatingBar.Small" or @style/Base.Widget.AppCompat.RatingBar.Indicator in the rating bar widget to play around with the colour of the rating star and the size as well.
– godslayer_69
Apr 25 '16 at 17:47
19
Doesn't work for Pre-lolipop.
– Malder
May 20 '16 at 7:47
1
is there any way to do this programmatically? i need to change star colour at runtime
– Євген Гарастович
Jan 10 '17 at 12:31
2
nevermind. found this awesome lib here: github.com/FlyingPumba/SimpleRatingBar we should give this man a medal. customizability is over the rooftop
– Євген Гарастович
Jan 11 '17 at 9:25
1
It is also working fine on KitKat.
– Parth Patel
Oct 25 '18 at 13:16
4
4
Along with the above answer, use style="@style/Base.Widget.AppCompat.RatingBar.Small" or @style/Base.Widget.AppCompat.RatingBar.Indicator in the rating bar widget to play around with the colour of the rating star and the size as well.
– godslayer_69
Apr 25 '16 at 17:47
Along with the above answer, use style="@style/Base.Widget.AppCompat.RatingBar.Small" or @style/Base.Widget.AppCompat.RatingBar.Indicator in the rating bar widget to play around with the colour of the rating star and the size as well.
– godslayer_69
Apr 25 '16 at 17:47
19
19
Doesn't work for Pre-lolipop.
– Malder
May 20 '16 at 7:47
Doesn't work for Pre-lolipop.
– Malder
May 20 '16 at 7:47
1
1
is there any way to do this programmatically? i need to change star colour at runtime
– Євген Гарастович
Jan 10 '17 at 12:31
is there any way to do this programmatically? i need to change star colour at runtime
– Євген Гарастович
Jan 10 '17 at 12:31
2
2
nevermind. found this awesome lib here: github.com/FlyingPumba/SimpleRatingBar we should give this man a medal. customizability is over the rooftop
– Євген Гарастович
Jan 11 '17 at 9:25
nevermind. found this awesome lib here: github.com/FlyingPumba/SimpleRatingBar we should give this man a medal. customizability is over the rooftop
– Євген Гарастович
Jan 11 '17 at 9:25
1
1
It is also working fine on KitKat.
– Parth Patel
Oct 25 '18 at 13:16
It is also working fine on KitKat.
– Parth Patel
Oct 25 '18 at 13:16
|
show 2 more comments
Simply add this line to xml
(API 21 and higher)
android:progressTint="@color/color"
add a comment |
Simply add this line to xml
(API 21 and higher)
android:progressTint="@color/color"
add a comment |
Simply add this line to xml
(API 21 and higher)
android:progressTint="@color/color"
Simply add this line to xml
(API 21 and higher)
android:progressTint="@color/color"
edited Jan 29 '17 at 16:39
mreza sh
5517
5517
answered Jan 10 '17 at 10:38
Raseem AyattRaseem Ayatt
390413
390413
add a comment |
add a comment |
As you mentioned that you want to change the star color without using the drawable. You can do it by few lines of code as below.
RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar);
Drawable drawable = ratingBar.getProgressDrawable();
drawable.setColorFilter(Color.parseColor("#0064A8"),PorterDuff.Mode.SRC_ATOP);
5
It draws 5 colored stars, not 3.5, for instance.
– CoolMind
Mar 16 '16 at 13:55
add a comment |
As you mentioned that you want to change the star color without using the drawable. You can do it by few lines of code as below.
RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar);
Drawable drawable = ratingBar.getProgressDrawable();
drawable.setColorFilter(Color.parseColor("#0064A8"),PorterDuff.Mode.SRC_ATOP);
5
It draws 5 colored stars, not 3.5, for instance.
– CoolMind
Mar 16 '16 at 13:55
add a comment |
As you mentioned that you want to change the star color without using the drawable. You can do it by few lines of code as below.
RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar);
Drawable drawable = ratingBar.getProgressDrawable();
drawable.setColorFilter(Color.parseColor("#0064A8"),PorterDuff.Mode.SRC_ATOP);
As you mentioned that you want to change the star color without using the drawable. You can do it by few lines of code as below.
RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar);
Drawable drawable = ratingBar.getProgressDrawable();
drawable.setColorFilter(Color.parseColor("#0064A8"),PorterDuff.Mode.SRC_ATOP);
edited Jan 10 '17 at 11:15
Ralf
10.4k94056
10.4k94056
answered Dec 29 '15 at 9:13
Chandra SharmaChandra Sharma
1,061922
1,061922
5
It draws 5 colored stars, not 3.5, for instance.
– CoolMind
Mar 16 '16 at 13:55
add a comment |
5
It draws 5 colored stars, not 3.5, for instance.
– CoolMind
Mar 16 '16 at 13:55
5
5
It draws 5 colored stars, not 3.5, for instance.
– CoolMind
Mar 16 '16 at 13:55
It draws 5 colored stars, not 3.5, for instance.
– CoolMind
Mar 16 '16 at 13:55
add a comment |
My task was change color of Rating Bar to the app's primary color for Android >=14 SDK. I've solved this problem in code and in xml file.
mRatingBar = (RatingBar)view.findViewById(R.id.ratingBar);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
try {
Drawable progressDrawable = mRatingBar.getProgressDrawable();
if (progressDrawable != null) {
DrawableCompat.setTint(progressDrawable, ContextCompat.getColor(getContext(), R.color.colorPrimary));
}
} catch (Exception e) {
e.printStackTrace();
}
}
And in xml file
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:backgroundTint="@color/colorPrimary"
android:numStars="5"
android:progressTint="@color/colorPrimary"
android:rating="0"
android:secondaryProgressTint="@android:color/transparent"
android:stepSize="1" />
add a comment |
My task was change color of Rating Bar to the app's primary color for Android >=14 SDK. I've solved this problem in code and in xml file.
mRatingBar = (RatingBar)view.findViewById(R.id.ratingBar);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
try {
Drawable progressDrawable = mRatingBar.getProgressDrawable();
if (progressDrawable != null) {
DrawableCompat.setTint(progressDrawable, ContextCompat.getColor(getContext(), R.color.colorPrimary));
}
} catch (Exception e) {
e.printStackTrace();
}
}
And in xml file
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:backgroundTint="@color/colorPrimary"
android:numStars="5"
android:progressTint="@color/colorPrimary"
android:rating="0"
android:secondaryProgressTint="@android:color/transparent"
android:stepSize="1" />
add a comment |
My task was change color of Rating Bar to the app's primary color for Android >=14 SDK. I've solved this problem in code and in xml file.
mRatingBar = (RatingBar)view.findViewById(R.id.ratingBar);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
try {
Drawable progressDrawable = mRatingBar.getProgressDrawable();
if (progressDrawable != null) {
DrawableCompat.setTint(progressDrawable, ContextCompat.getColor(getContext(), R.color.colorPrimary));
}
} catch (Exception e) {
e.printStackTrace();
}
}
And in xml file
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:backgroundTint="@color/colorPrimary"
android:numStars="5"
android:progressTint="@color/colorPrimary"
android:rating="0"
android:secondaryProgressTint="@android:color/transparent"
android:stepSize="1" />
My task was change color of Rating Bar to the app's primary color for Android >=14 SDK. I've solved this problem in code and in xml file.
mRatingBar = (RatingBar)view.findViewById(R.id.ratingBar);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
try {
Drawable progressDrawable = mRatingBar.getProgressDrawable();
if (progressDrawable != null) {
DrawableCompat.setTint(progressDrawable, ContextCompat.getColor(getContext(), R.color.colorPrimary));
}
} catch (Exception e) {
e.printStackTrace();
}
}
And in xml file
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:backgroundTint="@color/colorPrimary"
android:numStars="5"
android:progressTint="@color/colorPrimary"
android:rating="0"
android:secondaryProgressTint="@android:color/transparent"
android:stepSize="1" />
edited Apr 13 '17 at 8:47
answered Sep 22 '16 at 13:32
MalderMalder
1,7691934
1,7691934
add a comment |
add a comment |
try this,
You do need 3 star images (red_star_full.png, red_star_half.png and red_star_empty.png) and one xml file. If you want to golden star then use golden star image. this is for red star.
you can put ratingbar_color.xml in res/drawable.
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background" android:drawable="@drawable/red_star_empty" />
<item android:id="@android:id/secondaryProgress" android:drawable="@drawable/red_star_half" />
<item android:id="@android:id/progress" android:drawable="@drawable/red_star_full" />
</layer-list>
and in rating bar definition use following.
<RatingBar android:progressDrawable="@drawable/ratingbar_red/>
2
Duplicate of stackoverflow.com/questions/2446270/…
– turbandroid
Dec 25 '15 at 17:37
add a comment |
try this,
You do need 3 star images (red_star_full.png, red_star_half.png and red_star_empty.png) and one xml file. If you want to golden star then use golden star image. this is for red star.
you can put ratingbar_color.xml in res/drawable.
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background" android:drawable="@drawable/red_star_empty" />
<item android:id="@android:id/secondaryProgress" android:drawable="@drawable/red_star_half" />
<item android:id="@android:id/progress" android:drawable="@drawable/red_star_full" />
</layer-list>
and in rating bar definition use following.
<RatingBar android:progressDrawable="@drawable/ratingbar_red/>
2
Duplicate of stackoverflow.com/questions/2446270/…
– turbandroid
Dec 25 '15 at 17:37
add a comment |
try this,
You do need 3 star images (red_star_full.png, red_star_half.png and red_star_empty.png) and one xml file. If you want to golden star then use golden star image. this is for red star.
you can put ratingbar_color.xml in res/drawable.
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background" android:drawable="@drawable/red_star_empty" />
<item android:id="@android:id/secondaryProgress" android:drawable="@drawable/red_star_half" />
<item android:id="@android:id/progress" android:drawable="@drawable/red_star_full" />
</layer-list>
and in rating bar definition use following.
<RatingBar android:progressDrawable="@drawable/ratingbar_red/>
try this,
You do need 3 star images (red_star_full.png, red_star_half.png and red_star_empty.png) and one xml file. If you want to golden star then use golden star image. this is for red star.
you can put ratingbar_color.xml in res/drawable.
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background" android:drawable="@drawable/red_star_empty" />
<item android:id="@android:id/secondaryProgress" android:drawable="@drawable/red_star_half" />
<item android:id="@android:id/progress" android:drawable="@drawable/red_star_full" />
</layer-list>
and in rating bar definition use following.
<RatingBar android:progressDrawable="@drawable/ratingbar_red/>
answered Sep 28 '15 at 5:14
Ganpat KaliyaGanpat Kaliya
9491715
9491715
2
Duplicate of stackoverflow.com/questions/2446270/…
– turbandroid
Dec 25 '15 at 17:37
add a comment |
2
Duplicate of stackoverflow.com/questions/2446270/…
– turbandroid
Dec 25 '15 at 17:37
2
2
Duplicate of stackoverflow.com/questions/2446270/…
– turbandroid
Dec 25 '15 at 17:37
Duplicate of stackoverflow.com/questions/2446270/…
– turbandroid
Dec 25 '15 at 17:37
add a comment |
RatingBar ratingreview;
ratingreview=(RatingBar)v.findViewById(R.id.ratingreview);
ratingreview.setRating(Float.parseFloat(objrating));
Drawable drawable = ratingreview.getProgressDrawable();
drawable.setColorFilter(Color.parseColor("#6A9A28"), PorterDuff.Mode.SRC_ATOP);
add a comment |
RatingBar ratingreview;
ratingreview=(RatingBar)v.findViewById(R.id.ratingreview);
ratingreview.setRating(Float.parseFloat(objrating));
Drawable drawable = ratingreview.getProgressDrawable();
drawable.setColorFilter(Color.parseColor("#6A9A28"), PorterDuff.Mode.SRC_ATOP);
add a comment |
RatingBar ratingreview;
ratingreview=(RatingBar)v.findViewById(R.id.ratingreview);
ratingreview.setRating(Float.parseFloat(objrating));
Drawable drawable = ratingreview.getProgressDrawable();
drawable.setColorFilter(Color.parseColor("#6A9A28"), PorterDuff.Mode.SRC_ATOP);
RatingBar ratingreview;
ratingreview=(RatingBar)v.findViewById(R.id.ratingreview);
ratingreview.setRating(Float.parseFloat(objrating));
Drawable drawable = ratingreview.getProgressDrawable();
drawable.setColorFilter(Color.parseColor("#6A9A28"), PorterDuff.Mode.SRC_ATOP);
edited Jan 10 '17 at 12:33
Satan Pandeya
2,43231634
2,43231634
answered Dec 27 '16 at 7:02
Soumen DasSoumen Das
19515
19515
add a comment |
add a comment |
My use case was to show different colors for different ratings. For example :
1- Red
2- Orange
3- Yellow
4- Light Green
5- Dark Green
Solution :
ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(final RatingBar ratingBar, final float rating, final boolean fromUser) {
setCurrentRating(rating);
}
});
Then in your setCurrentRating()
method :
private void setCurrentRating(float rating) {
LayerDrawable drawable = (LayerDrawable)rateOverall.getProgressDrawable();
if(mContext!=null) {
switch (Math.round(rating)) {
case 1:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.dark_red));
break;
case 2:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.light_orange));
break;
case 3:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.light_yellow));
break;
case 4:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.light_green_review));
break;
case 5:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.dark_green));
break;
}
setRatingStarColor(drawable.getDrawable(1), ContextCompat.getColor(mContext, R.color.transparent));
setRatingStarColor(drawable.getDrawable(0), ContextCompat.getColor(mContext, R.color.light_grey_payment));
}
}
Then in your setRatingStarColor()
method:
private void setRatingStarColor(Drawable drawable, @ColorInt int color)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
DrawableCompat.setTint(drawable, color);
}
else
{
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
}
Thanks to this answer which helped me solve this.
Hope it helps someone !
add a comment |
My use case was to show different colors for different ratings. For example :
1- Red
2- Orange
3- Yellow
4- Light Green
5- Dark Green
Solution :
ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(final RatingBar ratingBar, final float rating, final boolean fromUser) {
setCurrentRating(rating);
}
});
Then in your setCurrentRating()
method :
private void setCurrentRating(float rating) {
LayerDrawable drawable = (LayerDrawable)rateOverall.getProgressDrawable();
if(mContext!=null) {
switch (Math.round(rating)) {
case 1:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.dark_red));
break;
case 2:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.light_orange));
break;
case 3:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.light_yellow));
break;
case 4:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.light_green_review));
break;
case 5:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.dark_green));
break;
}
setRatingStarColor(drawable.getDrawable(1), ContextCompat.getColor(mContext, R.color.transparent));
setRatingStarColor(drawable.getDrawable(0), ContextCompat.getColor(mContext, R.color.light_grey_payment));
}
}
Then in your setRatingStarColor()
method:
private void setRatingStarColor(Drawable drawable, @ColorInt int color)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
DrawableCompat.setTint(drawable, color);
}
else
{
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
}
Thanks to this answer which helped me solve this.
Hope it helps someone !
add a comment |
My use case was to show different colors for different ratings. For example :
1- Red
2- Orange
3- Yellow
4- Light Green
5- Dark Green
Solution :
ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(final RatingBar ratingBar, final float rating, final boolean fromUser) {
setCurrentRating(rating);
}
});
Then in your setCurrentRating()
method :
private void setCurrentRating(float rating) {
LayerDrawable drawable = (LayerDrawable)rateOverall.getProgressDrawable();
if(mContext!=null) {
switch (Math.round(rating)) {
case 1:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.dark_red));
break;
case 2:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.light_orange));
break;
case 3:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.light_yellow));
break;
case 4:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.light_green_review));
break;
case 5:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.dark_green));
break;
}
setRatingStarColor(drawable.getDrawable(1), ContextCompat.getColor(mContext, R.color.transparent));
setRatingStarColor(drawable.getDrawable(0), ContextCompat.getColor(mContext, R.color.light_grey_payment));
}
}
Then in your setRatingStarColor()
method:
private void setRatingStarColor(Drawable drawable, @ColorInt int color)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
DrawableCompat.setTint(drawable, color);
}
else
{
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
}
Thanks to this answer which helped me solve this.
Hope it helps someone !
My use case was to show different colors for different ratings. For example :
1- Red
2- Orange
3- Yellow
4- Light Green
5- Dark Green
Solution :
ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(final RatingBar ratingBar, final float rating, final boolean fromUser) {
setCurrentRating(rating);
}
});
Then in your setCurrentRating()
method :
private void setCurrentRating(float rating) {
LayerDrawable drawable = (LayerDrawable)rateOverall.getProgressDrawable();
if(mContext!=null) {
switch (Math.round(rating)) {
case 1:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.dark_red));
break;
case 2:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.light_orange));
break;
case 3:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.light_yellow));
break;
case 4:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.light_green_review));
break;
case 5:
setRatingStarColor(drawable.getDrawable(2), ContextCompat.getColor(mContext, R.color.dark_green));
break;
}
setRatingStarColor(drawable.getDrawable(1), ContextCompat.getColor(mContext, R.color.transparent));
setRatingStarColor(drawable.getDrawable(0), ContextCompat.getColor(mContext, R.color.light_grey_payment));
}
}
Then in your setRatingStarColor()
method:
private void setRatingStarColor(Drawable drawable, @ColorInt int color)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
DrawableCompat.setTint(drawable, color);
}
else
{
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
}
Thanks to this answer which helped me solve this.
Hope it helps someone !
answered Apr 24 '18 at 10:02
Shubham SrivastavaShubham Srivastava
1,208520
1,208520
add a comment |
add a comment |
Use this code to get over the line
Drawable drawableReview = writeReviewRatingBar.getProgressDrawable();
drawableReview.setColorFilter(Color.parseColor("#FFFDD433"), PorterDuff.Mode.SRC_ATOP);
add a comment |
Use this code to get over the line
Drawable drawableReview = writeReviewRatingBar.getProgressDrawable();
drawableReview.setColorFilter(Color.parseColor("#FFFDD433"), PorterDuff.Mode.SRC_ATOP);
add a comment |
Use this code to get over the line
Drawable drawableReview = writeReviewRatingBar.getProgressDrawable();
drawableReview.setColorFilter(Color.parseColor("#FFFDD433"), PorterDuff.Mode.SRC_ATOP);
Use this code to get over the line
Drawable drawableReview = writeReviewRatingBar.getProgressDrawable();
drawableReview.setColorFilter(Color.parseColor("#FFFDD433"), PorterDuff.Mode.SRC_ATOP);
answered Feb 19 at 7:06
Mohammad Shahzeb KhanMohammad Shahzeb Khan
767
767
add a comment |
add a comment |
Simple solution, use AppCompatRatingBar and use below code
ratingbar.setProgressTintList(ColorStateList.valueOf(ContextCompat.getColor(context, R.color.colorAccent)));
add a comment |
Simple solution, use AppCompatRatingBar and use below code
ratingbar.setProgressTintList(ColorStateList.valueOf(ContextCompat.getColor(context, R.color.colorAccent)));
add a comment |
Simple solution, use AppCompatRatingBar and use below code
ratingbar.setProgressTintList(ColorStateList.valueOf(ContextCompat.getColor(context, R.color.colorAccent)));
Simple solution, use AppCompatRatingBar and use below code
ratingbar.setProgressTintList(ColorStateList.valueOf(ContextCompat.getColor(context, R.color.colorAccent)));
answered Aug 3 '18 at 13:04
Kuldeep SakhiyaKuldeep Sakhiya
2,36111113
2,36111113
add a comment |
add a comment |
The simplest solution I have found is changing the color definition for the color "colorAccent" in the color.xml. That's entire magic without further coding.
add a comment |
The simplest solution I have found is changing the color definition for the color "colorAccent" in the color.xml. That's entire magic without further coding.
add a comment |
The simplest solution I have found is changing the color definition for the color "colorAccent" in the color.xml. That's entire magic without further coding.
The simplest solution I have found is changing the color definition for the color "colorAccent" in the color.xml. That's entire magic without further coding.
edited Nov 24 '18 at 12:48
answered Nov 24 '18 at 12:39
Stanislav VincentStanislav Vincent
30134
30134
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32810341%2fandroid-change-color-of-ratingbar-to-golden%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
does it mean changing the color of stars?
– Rahul Tiwari
Sep 27 '15 at 17:27
yes............................................
– ojas
Sep 27 '15 at 17:37
4
possible duplicate of Android RatingBar change star colors
– Rahul Tiwari
Sep 27 '15 at 17:46