Top Menu

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Tuesday 25 July 2017

Android Material Rating Bar - Rating Bar example in Material Design

Rating Bar

How to add?

I. In your build.gradle add latest appcompat library.
dependencies { compile
compile 'com.android.support:appcompat-v7:X.X.X' // where X.X.X version}
II. Make your activity extend android.support.v7.app.AppCompatActivity.
public class MainActivity extends AppCompatActivity { ...}
III. Declare your RatingBar inside any layout.xml file.
<RatingBar android:rating="3.5" android:stepSize="0.5" android:numStars="5" android:layout_width="wrap_content" android:layout_height="wrap_content"/>

How to style?


I. Declare custom style in your styles.xml file.
<style name="RatingBar" parent="Theme.AppCompat"> <item name="colorControlNormal">@color/indigo</item> <item name="colorControlActivated">@color/pink</item></style>
II. Apply this style to your RatingBar via android:theme attribute.

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

No comments:

Post a Comment