RSS

custom rating bar style using android’s ratingBar small style.

09 Feb

Go to res -> values in Android path and create a file is called style.xml

 

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="hotel_rating_bar_indicator" parent="@android:style/Widget.RatingBar.Indicator" >
    <item name="android:numStars">6</item>
    <item name="android:rating">4.5</item>
    <item name="android:stepSize">0.5</item>
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:paddingBottom">44dip</item>
    <item name="android:layout_marginLeft">4dip</item>
    <item name="android:layout_marginTop">4dip</item>
   </style>
   <style name="hotel_rating_bar" parent="@android:style/Widget.RatingBar" >
     <item name="android:numStars">6</item>
     <item name="android:rating">4.5</item>
     <item name="android:stepSize">0.5</item>
     <item name="android:layout_width">wrap_content</item>
     <item name="android:layout_height">wrap_content</item>
     <item name="android:paddingBottom">44dip</item>
     <item name="android:layout_marginLeft">4dip</item>
     <item name="android:layout_marginTop">4dip</item>
   </style>
   <style name="hotel_rating_bar_small" parent="@android:style/Widget.RatingBar.Small" >
     <item name="android:numStars">6</item>
     <item name="android:rating">4.5</item>
     <item name="android:stepSize">0.5</item>
     <item name="android:layout_width">wrap_content</item>
     <item name="android:layout_height">wrap_content</item>
     <item name="android:paddingBottom">44dip</item>
     <item name="android:layout_marginLeft">4dip</item>
     <item name="android:layout_marginTop">4dip</item>
   </style>
</resources>

 

main.xml


 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#000000">

        <LinearLayout android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:background="#000000">

                <TextView android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:textSize="14sp"
                    android:textStyle="bold"
                    android:textColor="#ffffff"
                    android:text="Rating Bar"
                    android:paddingLeft="4dp"/>
                <RatingBar 
                    android:id="@+id/hotel_rating_bar"
		    style="@style/hotel_rating_bar" />

                <TextView android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:textSize="14sp"
                    android:textStyle="bold"
                    android:textColor="#ffffff"
                    android:text="Rating Bar Indicator"
                    android:paddingLeft="4dp"/>
                <RatingBar 
                    android:id="@+id/hotel_rating_bar_indicator"
		    style="@style/hotel_rating_bar_indicator" />

              <TextView android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:textSize="14sp"
                    android:textStyle="bold"
                    android:textColor="#ffffff"
                    android:text="Rating Bar Small"
                    android:paddingLeft="4dp"/>
               <RatingBar 
                    android:id="@+id/hotel_rating_bar_small"
		    style="@style/hotel_rating_bar_small" />

       </LinearLayout>
</LinearLayout>

 

 

I get the same result on both (screen capture attached) where I can extend all three styles.

 

If this doesn’t work for you, you might try adding a version identifier to your res/values directory name, like res/values-v6 or res/values-v7. (But here I’m just guessing, based on a bug I’ve seen with images loading from res/drawable.)

 

But I wonder if you might want to upgrade your DROID to Android 2.2 (Froyo) or Android 2.3 (GIngerbread) ?

 

 

 

Copyright © 2011, Motorola Mobility, Inc. All rights reserved unless otherwise explicitly indicated. Sample source code written by Motorola Mobility, Inc. is provided to you under the conditions of the Motorola Modified BSD License (http://developer.motorola.com/docstools/library/bsd-license/).

 

Attachments:
rating-bar-1-50p.jpg
 

About sochinda

I really like new technology!!
Leave a comment

Posted by on February 9, 2012 in Android

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.