Xml file:
<RatingBar
android:id="#+id/row_item_rbRatingAvg"
style="#style/CustomRatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:isIndicator="true" />
Style file:
<style name="CustomRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/ratingstars</item>
<item name="android:minHeight">#dimen/rating_bar_height</item>
<item name="android:maxHeight">#dimen/rating_bar_height</item>
</style>
ratingstars.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+android:id/background"
android:drawable="#drawable/star_icon_a" />
<item android:id="#+android:id/secondaryProgress"
android:drawable="#drawable/star_icon_a" />
<item android:id="#+android:id/progress"
android:drawable="#drawable/star_icon" />
</layer-list>
dimens.xml
<dimen name="rating_bar_height">38px</dimen>
above files i used for set my custom ratingbar. i have also different size images for star_icon_a and star_icon. but still not working. in some devices, image get scaled and in some device image get cut. i dont know how to make for all screen sizes.
below is sample of drawable-xxhdpi size.
Related
Seems like there is no XML attribute to change the startIconDrawable size in android. The icon is oversized as compared to the text.
Here is a screenshot of the issue:
Here is my XML:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputLayout
style="#style/textInputStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Paypal ID"
android:padding="5dp"
app:endIconMode="clear_text"
app:startIconDrawable="#drawable/ic_paypal_logo">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/et_form_question_hint"
style="#style/textInputEditext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:paddingHorizontal="#dimen/normalPadding" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
If anyone wishes to reproduce styles are as follows:
<style name="textInputEditext" parent="FirebaseUI.TextInputEditText">
<item name="maxLine">1</item>
<item name="android:textColor">#color/colorOnSurface</item>
</style>
<style name="textInputStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="android:layout_marginBottom">12dp</item>
<item name="errorEnabled">true</item>
<item name="endIconTint">#color/colorSurface</item>
<item name="hintTextColor">#color/colorOnSurface</item>
<item name="shapeAppearance">#style/Cut</item>
<item name="boxStrokeColor">#AA000000</item>
<item name="android:textColorHint">#color/colorOnSurface</item>
<item name="android:textStyle">bold</item>
<item name="counterTextColor">#color/colorOnSurface</item>
<item name="android:textColor">#color/colorOnSurface</item>
</style>
There is no attribute to edit drawable size (until now).
However if you use the icon in many places in your code and you don't wanna mess with you original icon size, you can wrap it in an other drawable and change the item size there.
Here is an example:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:width="24dp" android:height="24dp"
android:drawable="#drawable/ic_yourIconName" />
</layer-list>
You can just change the size of your image.
For example, icon with size 48x48dp is twice as large as 24x24dp, look at the screenshots. (It also works with non-vector images)
Ratingbar star not showing properly.
i don't know what i am doing wrong with it.
when i used custom style then a single star is showing only and its length is equal to 5star.
<RatingBar
android:id="#+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="-15dp"
android:stepSize="1"
android:numStars="5"
style="#style/customRatingBar" />
Style is:
<style name="customRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/manual_ratingbar</item>
<item name="android:minHeight">32dip</item>
<item name="android:maxHeight">32dip</item>
</style>
manual_ratingbar file:
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background" android:drawable="#drawable/ic_star_unselect" />
<item android:id="#android:id/progress" android:drawable="#drawable/ic_star_select" />
</layer-list>
it looks like:
and when i changed the Ratingbar style to
style="?attr/ratingBarStyleIndicator"
then there is extra star visible in background.
what should i do?
#chandan you can resolve this issue by adding this on RatingBar Layout android:indeterminate="false"
I am trying to change the stars of my rating bar by creating new style, this what i did :
<style name="RatingBarSmall" parent="android:Widget.DeviceDefault.Light.RatingBar.Indicator">
<item name="android:progressDrawable">#drawable/rating_bar</item>
<item name="android:minHeight">36dp</item>
<item name="android:maxHeight">36dp</item>
</style>
drawable/rating_bar:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#android:id/background"
android:drawable="#drawable/rating_star_empty" />
<item
android:id="#android:id/secondaryProgress"
android:drawable="#drawable/rating_star_empty" />
<item
android:id="#android:id/progress"
android:drawable="#drawable/rating_star_filled" />
</layer-list>
rating bar xml view:
<RatingBar
android:id="#+id/ratingBar"
style="#style/RatingBarSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:isIndicator="true"
android:rating="5" />
and here is the tow images:
but i don't know why i got vertical lines under the stars as you can see int the bellow picture:
EDIT: SOLVED:i just set the rating bar height as the image height.
thanks
I observe this problem in this way. You may create any values in res/values/dimens.xml for each screen (mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi) like:
<dimen name="rating_min_height">36dp</dimen>
<dimen name="rating_min_width">36dp</dimen>
And use this:
<style name="RatingBarSmall" parent="android:Widget.DeviceDefault.Light.RatingBar.Indicator">
<item name="android:progressDrawable">#drawable/rating_bar</item>
<item name="android:minHeight">#dimen/rating_min_height</item>
<item name="android:maxHeight">#dimen/rating_min_width</item>
</style>
Or you can apply that logic to your drawable (rating_star_empty and rating_star_filled)
I am having a bit of a problem when setting a custom rating bar in android. I have followed this tutorial:
How to create Custom Ratings bar in Android
However I am experiencing an issue when changing/selecting more than 4 stars. The selected star image is misplaced a bit. Here is an image to show you what it looks like.
Here is my XML for creating the custom rating bar.
Main xml where the rating bar view is defined:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp"
android:gravity="center" >
<RatingBar
android:id="#+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="19dp"
android:numStars="50"
android:stepSize="1.0"
style="#style/AppCustomRatingBar"/>
Custom style for the RatingBar
<style name="AppCustomRatingBar"
parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/rating_stars_custom</item>
<item name="android:minHeight">19dp</item>
<item name="android:maxHeight">19dp</item>
</style>
rating_stars_custom.xml
<item
android:id="#android:id/background"
android:drawable="#drawable/rating_stars_yellow_empty" />
<item android:id="#android:id/secondaryProgress"
android:drawable="#drawable/rating_stars_yellow_empty" />
<item
android:id="#android:id/progress"
android:drawable="#drawable/rating_stars_yellow_full" />
rating_stars_yellow_empty.xml
<?xml version="1.0" encoding="utf-8"?>
<item
android:id="#android:id/background"
android:drawable="#drawable/rating_stars_yellow_empty" />
<item android:id="#android:id/secondaryProgress"
android:drawable="#drawable/rating_stars_yellow_empty" />
<item
android:id="#android:id/progress"
android:drawable="#drawable/rating_stars_yellow_full" />
rating_stars_yellow_full.xml
<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="#drawable/home_icon_star_fill_selected" />
<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="#drawable/home_icon_star_fill_selected" />
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="#drawable/home_icon_star_fill_selected" />
<item android:drawable="#drawable/home_icon_star_fill_selected" />
What am I doing wrong to misplace the stars? The image sizes of the stars (both yellow and white) are the same.
I managed to fix it. If you look at the picture I provided in my post above the yellow stars are like off with 1pix compared to empty stars. So I took a look at my pictures I use and their sizes. After that it appeared that the yellow star was 1pix shorter (in width) compared to the image with the empty star. So this was my problem I got new pictures of stars and I made sure they are the same size. Now I have 2 pictures 30x30 and all is OK! This fixed my problem! So my advice for people who are facing the same issue is to take a vary careful look at the size of the pictures they are using (empty/full) and make sure they are the same size. This way you save time and unnecessary coding. GL&HF :)
well I had the same problem with the rating bar. after doing some research I've found a way to overcome the above issue.
first, you need 2 stars, one empty star and one colored star. and size should be the same. (in my case both are 25x25)
then put this code in styles xml
<style name="redbar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/ratingbar_red</item>
<item name="android:minHeight">25dip</item>
<item name="android:maxHeight">25dip</item>
</style>
create another xml file called ratingbar_red.xml inside the drawable folder.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#+android:id/background"
android:drawable="#drawable/star_empty" />
<item android:id="#+android:id/secondaryProgress"
android:drawable="#drawable/star_empty" />
<item android:id="#+android:id/progress"
android:drawable="#drawable/star" />
</layer-list>
Finally crate your RatingBar like this.
<RatingBar
android:id="#+id/RatingBar05"
style="#style/redbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="false"
android:numStars="5"/>
this error || problem is actually related to the sizes of your images, Both have to be in the same size, the way I fixed this err is that I didn't remove the stoke or the border of the filled image, both images must have the same width and height
Recently my ToggleButtons on an application I'm working on lost it's green light indicator. I started with the various tutorials and got together a set of 9 patch indicators to make them work correctly again. The only problem is the text now sits on top of the indicator, like so:
I would like the text on top like the old toggle buttons...is there any way to do this?
btn_toggle_bg.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+android:id/background" android:drawable="#android:drawable/btn_default" />
<item android:id="#+android:id/toggle" android:drawable="#drawable/btn_toggle" />
</layer-list>
my btn_toggle.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="#drawable/btn_toggle_on" />
<item android:state_checked="false" android:drawable="#drawable/btn_toggle_off" />
</selector>
and the togglebutton tag in my activity:
<ToggleButton
android:background="#drawable/btn_toggle_bg"
style="#style/OurThemeName"
android:textOff="#string/fertilizer"
android:textOn="#string/fertilizer"
android:id="#+id/toggleFertilizer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false">
</ToggleButton>
<ToggleButton
android:background="#drawable/btn_toggle_bg"
style="#style/OurThemeName"
android:textOff="#string/irrigation"
android:textOn="#string/irrigation"
android:id="#+id/toggleIrrigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false">
</ToggleButton>
almost forgot the themes.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Overwrite the ToggleButton style -->
<style name="Widget.Button.Toggle" parent="android:Widget">
<item name="android:background">#drawable/btn_toggle_bg</item>
<item name="android:textOn">On</item>
<item name="android:textOff">Off</item>
<item name="android:disabledAlpha">?android:attr/disabledAlpha</item>
</style>
<style name="OurThemeName" parent="#android:Theme.Light">
<item name="android:buttonStyleToggle">#style/Widget.Button.Toggle</item>
<item name="android:textOn"></item>
<item name="android:textOff"></item>
</style>
</resources>
You need to set the Fill Area in your 9-Patch. You can add this areas including them in the right and bottom of your images using the Draw 9-patch tool. With this you are defining the area for your text label.
Check this tutorial explaining how 9-Patch works.