样式 Android 没有图标的 RatingBar 星星
Style Android RatingBar stars without icons
我在 Android 应用程序中有一个 RatingBar,星星采用应用程序的主要颜色。当我尝试从 here 扩展和更改此示例中的颜色时,它没有任何效果。
<style name="RatingBar" parent="Theme.AppCompat">
<item name="colorControlNormal">@color/indigo</item>
<item name="colorControlActivated">@color/pink</item></style>
有没有办法在不设置 progressDrawable
的情况下自定义此颜色
这是主色的结果。
EDIT 发现了问题。我正在尝试以下几行
theme="@style/RatingBar"
或
style="@style/RatingBar"
但是应该在我忘记 android
关键字的地方使用它
正确的用法解决了我的问题:
android:theme="@style/RatingBar"
1.In 你的 build.gradle 添加最新的应用压缩库。
dependencies {
compile 'com.android.support:appcompat-v7:X.X.X' // where X.X.X version
}
2.Make 你的 activity 扩展 android.support.v7.app.AppCompatActivity.
public class MainActivity extends AppCompatActivity {
...
}
3.Declare 在您的 styles.xml 文件中自定义样式。
<style name="RatingBar" parent="Theme.AppCompat">
<item name="colorControlNormal">@color/indigo</item>
<item name="colorControlActivated">@color/pink</item></style>
4.Apply 通过 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"/>
我在 Android 应用程序中有一个 RatingBar,星星采用应用程序的主要颜色。当我尝试从 here 扩展和更改此示例中的颜色时,它没有任何效果。
<style name="RatingBar" parent="Theme.AppCompat">
<item name="colorControlNormal">@color/indigo</item>
<item name="colorControlActivated">@color/pink</item></style>
有没有办法在不设置 progressDrawable
这是主色的结果。
EDIT 发现了问题。我正在尝试以下几行
theme="@style/RatingBar"
或
style="@style/RatingBar"
但是应该在我忘记 android
关键字的地方使用它
正确的用法解决了我的问题:
android:theme="@style/RatingBar"
1.In 你的 build.gradle 添加最新的应用压缩库。
dependencies {
compile 'com.android.support:appcompat-v7:X.X.X' // where X.X.X version
}
2.Make 你的 activity 扩展 android.support.v7.app.AppCompatActivity.
public class MainActivity extends AppCompatActivity {
...
}
3.Declare 在您的 styles.xml 文件中自定义样式。
<style name="RatingBar" parent="Theme.AppCompat">
<item name="colorControlNormal">@color/indigo</item>
<item name="colorControlActivated">@color/pink</item></style>
4.Apply 通过 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"/>