[英]How to resize (stretch) Android RatingBar without adding more Stars
[英]Style Android RatingBar stars without icons
我在Android应用程序中有一个RatingBar,其中星星采用应用程序的主要颜色。 当我尝试从此处扩展和更改此示例中的颜色时,它没有任何效果。
<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"
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"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.