2016-10-07 4 views
1

Ich habe einen RatingBarBewertungsleiste Farbdifferenz auf verschiedenen Geräten

 <android.support.v7.widget.AppCompatRatingBar 
      android:id="@+id/rating" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:isIndicator="false" 
      android:numStars="5" 
      android:rating="0.0" 
      android:stepSize="1.0" 
      android:theme="@style/RatingBar"/> 

und Stil:

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

Das Problem ist, dass dieser Stil aus irgendwelchen Gründen ignoriert:

Nexus 5x API 24 : enter image description here

Samsu ng S4 API 21:

enter image description here

Meine Tätigkeit ist extends FragmentActivity vielleicht ist das Problem hier? Wie repariert man?

+0

Creat e custom Bewertungsleiste –

+0

Mögliches Duplikat von [RatingBar Theme funktioniert in Marshmallow, aber nicht in Lollipop] (http://stackoverflow.com/questions/39911082/ratingbar-theme-working-in-marshmallow-but-not-in-lollipop) –

Antwort

2

Von API 21 und über Sie es einfach aus xml

ändern nach Gerät
android:progressTint="@android:color/holo_red_dark" 
android:progressBackgroundTint="@android:color/holo_red_dark" 
android:secondaryProgressTint="@android:color/holo_red_dark" 
0

Sie die Version des Geräts zu finden, indem

int so zum einen die Farbe der Bewertungsleiste ändern androidVersion = Integer.parseInt (android.os.Build.VERSION.RELEASE); danach

Drawbar ziehbar = ratingBar.getProgressDrawable(); drawable.setColorFilter (Color.parseColor ("#" + androidVersion/Create_color_via_ androidVersion _with_the_help_of_Random_JAVA_class /), PorterDuff.Mode.SRC_ATOP);

0

Versuchen Sie, die gleiche Farbe für beide colorControlNormal bieten und colorControlActivated

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

ERGEBNIS:
1. Nexus 5 enter image description here 2. Auf Samsung S4 enter image description here

Ich weiß nicht, warum das passiert, aber Sie können Ihr Ergebnis haben.

1

schließlich nach viel versuche ich die Lösung bekam: Statt android:theme="@style/RatingBar" Verwendung mit style="@style/RatingBar"

und

android:progressTint="yourColor" android:progressBackgroundTint="@color/yourColor" android:secondaryProgressTint="@color/yourColor"

für Füllung, Teil- und leere Farbe des Sterns in der Bewertung Leiste. Es funktioniert in beiden Geräten gleich.

und Stil sollte

<style name="RatingBar" parent="android:style/Widget.Material.RatingBar.Small"> 
<item name="colorControlNormal">@color/yourColor</item> 
<item name="colorControlActivated">@color/yourColor</item></style> 
-1
public void setRatingBar(RatingBar ratingBar) { 
    LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable(); 
    stars.getDrawable(2).setColorFilter(mContext.getResources().getColor(R.color.rating_yellow), PorterDuff.Mode.SRC_ATOP); 
    stars.getDrawable(0).setColorFilter(mContext.getResources().getColor(R.color.grey_text), PorterDuff.Mode.SRC_ATOP); 
    stars.getDrawable(1).setColorFilter(mContext.getResources().getColor(R.color.rating_yellow), PorterDuff.Mode.SRC_ATOP); 
} 

Verwendung obige Verfahren sein und dies als Rating Ansicht verwenden, bevor Sie Rate rating bar unten.

setRatingBar(ratingView); 

Fügen Sie diese für mich

<RatingBar 
    android:id="@+id/ratingBar" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_vertical" 
    android:isIndicator="true" 
    android:numStars="5" 
    android:scaleX="0.5" 
    android:scaleY="0.5" 
    android:stepSize="1" 
    android:theme="@style/RatingBar" /> 

Es funktioniert gut zu rating bar

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

und setzen diese als Thema styles.xml ... Hoffe, es funktioniert gut für dich auch

Verwandte Themen