【问题标题】:Styling rating bar not working样式评分栏不起作用
【发布时间】:2016-02-20 06:51:39
【问题描述】:

我正在尝试设置评分栏的样式。我为评分栏创建了样式并将其添加到我的评分栏。但是评分栏忽略了它的风格并从 AppTheme 中挑选出来。 这是两种风格

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="colorControlNormal">#ffffff</item>
</style>
    <style name="MyMaterialTheme" parent="AppTheme"/>
    <style name="foodRatingBar" parent="@android:style/Widget.RatingBar">
        <item name="android:progressDrawable">@drawable/rating_stars</item>
        <item name="android:minHeight">48dip</item> <!-- your desired size -->
        <item name="android:maxHeight">48dip</item> <!-- your desired size -->
    </style>

rating_stars.xml

<?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_selected" />
    <item android:id="@android:id/secondaryProgress"
        android:drawable="@drawable/star_selected" />
    <item android:id="@android:id/progress"
        android:drawable="@drawable/stsr" />
</layer-list>

评分栏 xml

<RatingBar
    android:theme="@style/foodRatingBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="5dp"
    android:numStars="5"
    android:isIndicator="false" />

在应用此样式时,它仍然从 AppTheme 中选择颜色:colorCntrolNormal、colorAccent。 这种方式是错误的还是我错过了什么?

【问题讨论】:

  • 使用 android:theme="@style/yourTheme"
  • 我已经在用了
  • 然后尝试将其放入您的评分栏主题 @color/RatingAccentColor

标签: android ratingbar


【解决方案1】:

改变

<RatingBar
android:theme="@style/foodRatingBar"/>

<RatingBar
android:theme="@style/MyMaterialTheme"/>

<RatingBar
style="@style/foodRatingBar"/>

目前您正在为主题属性分配样式,但女巫不起作用

【讨论】:

    【解决方案2】:

    您可以使用 colorfilter() 更改星形颜色运行时。试试这个

    LayerDrawable stars = (LayerDrawable) rb_Ratings.getProgressDrawable();
    stars.getDrawable(2).setColorFilter(getActivity().getResources().getColor(R.color.primary_alpha_600),
                    PorterDuff.Mode.SRC_ATOP);
    

    【讨论】:

      猜你喜欢
      • 2016-06-01
      • 2012-12-24
      • 2017-01-17
      • 1970-01-01
      • 1970-01-01
      • 2014-07-14
      • 2018-09-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多