RatingBar with pink background when holding - android

My RatingBar is pretty regular, when selected appears like this
But when touching (and holding) them, all unrated stars are pink, like this
Why does this happen?
The xml:
<RatingBar
android:id="#+id/ratingBarSchedulesRatingTour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:numStars="5"
android:progressTint="#color/yellow_star"
android:secondaryProgressTint="#color/yellow_star"
android:stepSize="1" />
#color/yellow_star is on colors.xml as #F1CD1E

You can use android:progressBackgroundTint attribute on RatingBar to override background color:
android:progressBackgroundTint="#ABABAB"

Create Style and color what you want (press/normal)
<style name="RatingBar" parent="Theme.AppCompat">
<item name="colorControlNormal">#F1CD1E</item>
<item name="colorControlActivated">#F1CD1E</item>
</style>
<RatingBar
android:id="#+id/ratingBarSchedulesRatingTour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:numStars="5"
android:progressTint="#F1CD1E"
android:theme="#style/RatingBar"
android:secondaryProgressTint="#F1CD1E"
android:stepSize="1" />

Related

Change or remove RatingBar focus color

I have RatingBar and style. I want to remove focusing color at the RatingBar.
My empty RatingBar's colors:
My RatingBar's focusing color:
I want to remove focusing color:
theme:
<style name="CustomRatingBar" parent="Theme.AppCompat">
<item name="colorControlNormal">#color/lightTransparentBlack</item>
<item name="colorControlActivated">#color/yellow</item>
</style>
layout:
<RatingBar
android:id="#+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:theme="#style/CustomRatingBar"
android:layout_marginTop="20dp"
android:numStars="5"
android:stepSize="1" />
On API 21 and higher, you can change the color of the filled stars with
android:progressTint="#color/color"
and the color of the stroke with
android:progressBackgroundTint="#color/color"

RatingBar Theme working in Marshmallow but not in Lollipop

I am trying to style my RatingBar with the following code:
<style name="RatingBarfeed" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">#color/white</item>
<item name="colorControlActivated">#color/duskYellow</item>
</style>
And in layout.xml I am using the following code:
<android.support.v7.widget.AppCompatRatingBar
android:theme="#style/RatingBarfeed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/ratingBarStyleSmall"
android:id="#+id/ratingBar"
android:paddingBottom="0.45dp"
app:layout_constraintTop_toTopOf="#+id/rating"
app:layout_constraintLeft_toRightOf="#+id/rating"
app:layout_constraintBottom_toBottomOf="#+id/rating"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.0"
android:background="#color/orange"
android:rating="3.5"
android:stepSize="0.5"/>
Its working fine in Marshmallow (check the screenshot)
But in Lollipop Theme is not working (check the screenshot)
Please Help...!!!!
After much struggle I got my answer:
it should be style="#style/RatingBarfeed" instead of android:theme+"#style/RatingBarfeed"
For styling star fill, empty and partial color
android:progressTint="#F9BB28"
android:progressBackgroundTint="#color/white"
android:secondaryProgressTint="#color/white"
Final code should be like
<android.support.v7.widget.AppCompatRatingBar
android:layout_width="wrap_content"
android:layout_height="18dp"
style="#style/RatingBarfeed"
android:id="#+id/ratingBar"
android:gravity="center"
android:progressTint="#F9BB28"
android:progressBackgroundTint="#color/white"
android:secondaryProgressTint="#color/white"
app:layout_constraintTop_toTopOf="#+id/rating"
app:layout_constraintLeft_toRightOf="#+id/rating"
app:layout_constraintBottom_toBottomOf="#+id/rating"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.0"
android:background="#color/orange"
android:rating="3.5"
android:stepSize="0.1"/>
Style should be:
<style name="RatingBarfeed" parent="android:style/Widget.Material.RatingBar.Small">
<item name="colorControlNormal">#color/white</item>
<item name="colorControlActivated">#color/duskYellow</item>
</style>

How to set the colors of Android small RatingBar

I am trying to set a custom color for the small progressbar with this code:
<style name="RatingBar" parent="Theme.AppCompat">
<item name="colorControlNormal">#color/gold_yellow</item>
<item name="colorControlActivated">#color/light_grey</item>
</style>
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="true"
android:rating="3.3"
android:theme="#style/RatingBar"
android:id="#+id/go_rating"
style="#android:style/Widget.Holo.Light.RatingBar.Small"/>
The problem with this is this: the stars are small quite alright but they are blue. But If I remove style="#android:style/Widget.Holo.Light.RatingBar.Small then the color becomes golden yellow but it becomes big.
Please how do I set custom colors for the stars and at the same time make it small?
Use style="?attr/ratingBarStyleSmall" style:
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="true"
android:rating="3.3"
android:theme="#style/RatingBar"
android:id="#+id/go_rating"
style="?attr/ratingBarStyleSmall"/>
see also: https://stackoverflow.com/a/3173594/5183999

RatingBar with small white stars

The following is the xml for my rating bar.
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/ratingBarStyleSmall"
android:numStars="5"
android:isIndicator="true"
android:stepSize="0.5"
android:rating="4.5"/>
I am happy with its size but I would like to stars to be white on grey (white for filled and grey for empty).
I am looking at this tutorial (http://www.materialdoc.com/rating-bar/) but I am not sure how to adapt the style to suit the small appearance.
You can try 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/star_off" />
<item android:id="#android:id/secondaryProgress"
android:drawable="#drawable/star_off" />
<item android:id="#android:id/progress"
android:drawable="#drawable/star_on" />
</layer-list>
<RatingBar
android:id="#+id/ratingBar2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:progressDrawable="#drawable/custom_ratingbar_selector"
android:isIndicator="true"
android:stepSize="0.5"
android:rating="4.5" />
you can use progressTint for this purpose
<RatingBar
android:id="#+id/vendorRatingBarValue"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignRight="#+id/reviewerName"
android:clickable="false"
android:gravity="left|center"
android:isIndicator="true"
android:numStars="5"
android:progressTint="#color/white"
android:transformPivotX="0dp"
/>
you would need to use the attributes
android:backgroundTint="#color/grey"
android:progressTint="#color/white"
so..
<RatingBar
android:id="#+id/rb_doctor"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:backgroundTint="#color/grey"
android:numStars="5"
android:progressTint="#color/white"
android:rating="0"
android:secondaryProgressTint="#color/white"
android:stepSize="1.0"
/>
This is simple example of RatingBar.
Custom white and gray star can possible with custom theme for this and specify small size so size of rating bar star will be same as default small size theme.
You have to create drawable for custom rating bar and make sure about the size of rating bar because here height of rating bar matters a lot.i mean if your star image is size of 13dp height and rating bar is 17dp height than it will stretch the rating bar so make sure about height.
Here is simple example of how can create custom selector for rating bar.
Star Drawable
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:state_window_focused="true" android:drawable="#drawable/ic_star_empty_small" />
<item android:state_focused="true" android:state_window_focused="true" android:drawable="#drawable/ic_star_empty_small" />
<item android:state_selected="true" android:state_window_focused="true" android:drawable="#drawable/ic_star_empty_small" />
<item android:drawable="#drawable/ic_star_empty_small" />
</selector>
Style for rating bar
<style name="foodRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/inf_full_ratingbar</item>
<item name="android:minHeight">20dip</item>
<item name="android:width">20dip</item>
<item name="android:height">20dip</item>
<item name="android:maxHeight">20dip</item>
</style>
And than use custom style for rating bar like:
<RatingBar
android:id="#+id/ratingBarFlight"
style="#style/StarRatingBar"
android:layout_width="wrap_content"
android:layout_height="#dimen/rating_bar_height"
android:layout_gravity="center_horizontal"
android:layout_marginTop="#dimen/library_screen" />

How to remove the RatingBar star border stroke in Android?

I am using RatingBar in my application. For this rating bar app star I am getting the border stroke. How can I remove this border stroke? Below are my xml and screenshot of the bar.
<RatingBar
android:id="#+id/rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/ratingBarStyleSmall"
android:numStars="5"
android:stepSize="0.8"
android:scaleX="0.8"
android:scaleY="0.8"
android:isIndicator="true"
android:layout_marginStart="60dp"
android:layout_marginEnd="17dp"
android:layout_marginTop="4dp"
android:layout_below="#+id/userName" />
you need custom your ratingbar and provide your own images,default ratingbar's image contain border stroke:
<style name="RatingBarStyle" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/ratingbar_selector</item>
<item name="android:minHeight">34dp</item>
<item name="android:maxHeight">34dp</item>
</style>
<item android:id="#+android:id/background"
android:drawable="#drawable/emotion_composer_rating_small_icon" />
<item android:id="#+android:id/secondaryProgress"
android:drawable="#drawable/emotion_composer_rating_small_icon" />
<item android:id="#+android:id/progress"
android:drawable="#drawable/emotion_composer_rating_small_icon_highlighted" />

Categories

Resources