【问题标题】:Style Android RatingBar stars without icons样式 Android RatingBar 没有图标的星星
【发布时间】:2016-10-12 15:41:33
【问题描述】:

我在 Android 应用程序中有一个 RatingBar,其中的星星采用应用程序的原色。当我尝试从here 扩展和更改此示例中的颜色时,它没有任何效果。

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

有没有办法在不设置progressDrawable的情况下自定义这种颜色

这是原色的结果。

编辑发现问题。我正在尝试以下几行

theme="@style/RatingBar"

style="@style/RatingBar"

但是这应该用在我忘记了android关键字的地方

正确的用法解决了我的问题:

android:theme="@style/RatingBar"

【问题讨论】:

  • 告诉我你如何在你的 xml 中使用这种评级栏样式?
  • @BhavdipSagar 您能否添加一个答案,因为您的提示给了我一个找到问题的想法。我已经更新了问题并写了问题所在。

标签: android styles themes ratingbar


【解决方案1】:

1.在你的 build.gradle 中添加一个最新的应用压缩库。

dependencies {  
    compile 'com.android.support:appcompat-v7:X.X.X' // where X.X.X version
}

2.使您的活动扩展 android.support.v7.app.AppCompatActivity。

public class MainActivity extends AppCompatActivity {  
    ...
}

3.在你的styles.xml文件中声明自定义样式。

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

4.通过 android:theme 属性将此样式应用于您的 RatingBar。

   <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"/>

【讨论】:

    猜你喜欢
    • 2010-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-26
    • 1970-01-01
    相关资源
    最近更新 更多