如何在 ListView 中设置 RatingBar 的样式? (API 21 及以下的问题)

How to style RatingBar inside ListView? (Problems in API 21 and low)

我在相对布局中有一个 RatingBar:

好的,灰色和金色的星星。 https://www.dropbox.com/s/22y8117fwyv969x/Stars23.JPG?dl=0

但是如果我在 ListView 中有相同的 RatingBar,结果是:

问题是什么?我该如何解决?有什么想法吗?

代码:

<RatingBar
    android:id="@+id/ratings_list_item_ratingBar"
    style="@style/Widget.AppCompat.RatingBar.Small"
    android:theme="@style/RatingBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:isIndicator="true"
    android:numStars="5"
    android:stepSize="1"/>

styles.xml 中的样式:

<style name="RatingBar" parent="Theme.AppCompat">
    <item name="colorControlNormal">@android:color/darker_gray</item>
    <item name="colorControlActivated">@color/Yelow200</item>
</style>

适配器:

public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater) context
                            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View rowView = inflater
                            .inflate(R.layout.ratings_list_item, parent, false);
            RatingBar ratingBar = (RatingBar) rowView.findViewById(R.id.ratings_list_item_ratingBar);
            float ratingNumber = (float)values.get(position).getRating();
            ratingBar.setRating(ratingNumber);
            return rowView;
    }

您正在使用的 LayoutInflater 可能没有注意到您的应用程序的 style.xml。

尝试使用以下 LayoutInflater(抱歉,之前无法对此进行测试,但它在类似情况下有所帮助):

LayoutInflater inflater = LayoutInflater.from(parent.getContext());