Small Style Custom rating bar (readonly custom rating bar) - android

I tried to create a custom rating bar. I don't use style because I only use this once. So, I created a layer-list in the drawable folder (its name is custom_rating_bar.xml):
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#android:id/background"
android:drawable="#drawable/custom_icon_empty"/>
<item
android:id="#android:id/secondaryProgress"
android:drawable="#drawable/custom_icon_empty"/>
<item
android:id="#android:id/progress"
android:drawable="#drawable/custom_icon"/>
</layer-list>
And I use this code in the rating bar to use those icons:
android:progressDrawable="#drawable/custom_rating_bar"
My image size is standard (48x48 for mdpi, etc) and i use a small style rating bar :
style="?android:attr/ratingBarStyleSmall"
The problem is, i cant use style="?android:attr/ratingBarStyleSmall" together with android:progressDrawable (When i did this, the images will not shown). When i delete the style (style="?android:attr/ratingBarStyleSmall") my rating bar become too big (the images are shown).
This image show how big is it (i think the margin between image is also too much) :
So, how to make my custom rating bar smaller? (as small as the default small style rating bar).
And this custom rating bar is for show only (cant be changed by user).
Thanks.

First off, remove the "+"s from your android:id. Also, you may want to add a style in your xml, such as style="?android:attr/progressBarStyleHorizontal" depending on your needs. You might also need to use android:indeterminateDrawable="#drawable/custom_rating_bar" instead of progressDrawable

Related

Android Progress bar set level

I am trying to change the progress bar color based on different levels.
Drawable used by the progress bar
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:maxLevel="1" android:drawable="#drawable/progress_horizontal_green"/>
<item android:maxLevel="2" android:drawable="#drawable/progress_horizontal_red"/>
</layer-list>
I am loading the progress bar like so:
// viewHolder.budgetProgress is a ProgressBar
viewHolder.budgetProgress.setMax(100);
// No matter what level I change, the drawable used is always the lowest one.
viewHolder.budgetProgress.getProgressDrawable().setLevel(0);
viewHolder.budgetProgress.setProgress(95);
The problem is that the drawable used is always the lowest one, so in this case red. If I swap the progress_horizontal_red and progress_horizontal_green around, then the progress bar is always green.
There is a good tutorial : Progress bar implementation using Level list drawable

Smaller Custom RatingBar: Material Design

I am building an app which uses a non-clickable (indicator) ratingbar. Now, when the ratingbar IS clickable, it has two different modes. When clicked the icons turn red (red is the accentColor in my styles). When not clicked, the stars are an ugly gray with a black outline. When a rating bar is set to unclickable (indicator), the stars are permanently black-and-gray.
Additionally, I would like to make the stars smaller. Can I do both of the above things without defining custom drawables? If I must define custom drawables, how can I access the preexisting "clicked star" drawable, so that I do not need to create my own?
Thanks
<RatingBar
style="#style/RatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:rating="3.5"
android:stepSize="0.5" />
and add this in your styles xml file
<style name="RatingBar"
parent="android:style/Widget.Material.RatingBar.Small">
<item name="colorControlNormal">#color/primary_light</item>
<item name="colorControlActivated">#color/primary_dark</item>
</style>
visit my Blog Post and see working example. This way you dont need to customise ratingBar.

Action bar action button icon size

Our app uses Action Bar Sherlock, and it has a theme like such:
<style name="Theme.MyApp.Default" parent="#style/Theme.Sherlock.Light">
<item name="actionButtonStyle">#style/MyApp.SherlockActionBar.Light.ActionButton</item>
<item name="android:actionButtonStyle">#style/MyApp.SherlockActionBar.Light.ActionButton</item>
</style>
<style name="MyApp.SherlockActionBar.Light.ActionButton" parent="#style/Widget.Sherlock.Light.ActionButton">
<item name="android:maxHeight">20dp</item>
<item name="android:maxWidth">20dp</item>
</style>
Where Theme.MyApp.Default is the default theme for the app.
I need to set the icons for the action buttons (#2 on this image) to be a specific size. When I set the height/width/scaleX/scaleY/scaleType/padding properties however, the icon on the button still maintain what looks like their pixel size. The text part of the action button does seems to adhere to the setting though. Could it just be a compound drawable on a textview?
How can I set the size of the icon on the action bar?
Action bar icons for phones should be 32x32 dp.
Action bar icons are graphic buttons that represent the most important actions people can take within your app. Each one should employ a simple metaphor representing a single concept that most people can grasp at a glance.
you refer that link here
Have you cleaned your project and then run?
and you can specify action item height in main.xml(actionbar menu layout ) also though contrl space wont wrk its like normal height prperty.
whenever changing styles you have to clean and run the project
More and more evidence points to the fact that the menu on the action bar is a compound drawable. (Setting the property android:drawablePadding moves the icon from the text.) And seeing that you can't scale the image in XML for a compound drawable, this doesn't seem possible at the moment.

Different drawables for split actionbar

Is there a way to provide a different drawable icon if menu items are pushed to the split actionbar? My split action bar color differs to much from the top bar and a single icon style is not as visually please as I would hope.
Put the Drawables that you want to use for split in /res/drawable/ and put the others in /res/drawable-w480dp.
You can use LevelListDrawable for the icons and set the level when the screen configuration changes (which means Activity.onCreate()is called.
Create a drawable to be used in the icons with
<level-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:maxLevel="0" android:drawable="#drawable/**your bitmap dark**" />
<item android:maxLevel="1" android:drawable="#drawable/**your bitmap light**" />
</level-list>
Detect, if ActionBar is splitted or not. This part seems to be tricky. I'm using SherlockActionBar and there it works (up to todays Android Version) this way
To change one drawable, set on the corresponding ActionBar.Tab the level with getIcon().setLevel(). Note that you do not need to cast to LevelListDrawable. For whatever reason the level concept is implemented directly with the Drawable class.
In the appcompat library the split ActionBar is used in configurations other than large, land or sw480dp. If youre using the native ActionBar i guess you can skip the large configuration.
Then, to provide alternative drawables you should define appropriate references in these values dirs, like:
In values:
<item name="action_search_drawable" type="drawable" format="reference">#drawable/ic_action_search_narrow</item>
In values-w480dp:
<item name="action_search_drawable" type="drawable" format="reference">#drawable/ic_action_search</item>
Then, in the menu configuration you should use this reference as the icon drawable.

Android custom rating bar image size problem

Iam building a custom rating bar. With help of kozyr's article i have created it.
But i have an issue with different image scaling sizes for different screen types.
Below i provide image with screenshots of my custom rating bar in the left, and simple imageview to the right.
This is for HVGA screen.
link to screenshot
As you see, stars in rating bar and in the imageview are the same
And this screenshot from HVGA screen
another link to the screenshot
Android somehow resizes stars in my ratingbar. What is the problem?!!
Here is the code
<RatingBar android:id="#+id/rating_lunch" style="#style/starRatingBar" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:numStars="5" android:stepSize="1.0"/>
Here goes the style:
<style name="starRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/progress_star_big</item>
<item name="android:minHeight">19px</item>
<item name="android:maxHeight">19px</item>
</style>
Try using device independent pixels instead of actual pixels. e.g.:
<item name="android:maxHeight">19dp</item>
See the docs on this topic.
Problem solved. When i added
<uses-sdk android:minSdkVersion="4"
android:targetSdkVersion="7" />
to the manifest file everything became allright)

Categories

Resources