I have a RatingBar in Android application on which the stars take the primary color of the application. When I try to extend and change the colors like in this example from here it doesn't have any effect.
<style name="RatingBar" parent="Theme.AppCompat">
<item name="colorControlNormal">@color/indigo</item>
<item name="colorControlActivated">@color/pink</item></style>
Is there a way to customize this colors without setting progressDrawable
Here is the result with the primary color.
EDIT found the issue. I was trying the following lines
theme="@style/RatingBar"
or
style="@style/RatingBar"
but instead this should be used where I have forgotten the android
keyword
The correct usage solved my issue:
android:theme="@style/RatingBar"
1.In your build.gradle add a latest app compact library.
dependencies {
compile 'com.android.support:appcompat-v7:X.X.X' // where X.X.X version
}
2.Make your activity extend android.support.v7.app.AppCompatActivity.
public class MainActivity extends AppCompatActivity {
...
}
3.Declare custom style in your styles.xml file.
<style name="RatingBar" parent="Theme.AppCompat">
<item name="colorControlNormal">@color/indigo</item>
<item name="colorControlActivated">@color/pink</item></style>
4.Apply this style to your RatingBar via android:theme attribute.
<RatingBar
android:theme="@style/RatingBar"
android:rating="3"
android:stepSize="0.5"
android:numStars="5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>