Change or remove RatingBar focus color - android

I have RatingBar and style. I want to remove focusing color at the RatingBar.
My empty RatingBar's colors:
My RatingBar's focusing color:
I want to remove focusing color:
theme:
<style name="CustomRatingBar" parent="Theme.AppCompat">
<item name="colorControlNormal">#color/lightTransparentBlack</item>
<item name="colorControlActivated">#color/yellow</item>
</style>
layout:
<RatingBar
android:id="#+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:theme="#style/CustomRatingBar"
android:layout_marginTop="20dp"
android:numStars="5"
android:stepSize="1" />

On API 21 and higher, you can change the color of the filled stars with
android:progressTint="#color/color"
and the color of the stroke with
android:progressBackgroundTint="#color/color"

Related

How to tint the color of the shadow in Android Switch?

I'm using Material Switch, and I know how to change the colors of the track and the thumb, but how do you change the color of the radiant shadow?
I have changed the color to purple, but when I tap on it, there is still that green shadow. I've tried styles, appcompat switch, etc but nothing worked.
Here is my code:
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="#+id/switch_compat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:trackTint="#color/purple_500"
app:thumbTint="#color/purple_700"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Thanks!
You can change the color of the ripple using
<item name="colorControlHighlight">#color/purple_700</item>
But you will need to define two styles for this either in styles.xml or themes.xml:
<style name="SelectableItemBackgroundBorderless">
<item name="android:theme">#style/SelectableItemTheme</item>
<item name="android:background">?attr/selectableItemBackgroundBorderless</item>
</style>
<style name="SelectableItemTheme">
<item name="colorControlHighlight">#color/purple_700</item>
</style>
Then define style attribute for you switch:
style="#style/SelectableItemBackgroundBorderless"
So your Switch will be:
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="#+id/switch_compat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:trackTint="#color/purple_500"
app:thumbTint="#color/purple_700"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
style="#style/SelectableItemBackgroundBorderless" />
EDIT:
You can change the color of ripple on OFF state and ON state. No need to use the first style. Just define theme, no need to define style:
android:theme="#style/SelectableItemTheme"
Define in styles:
<style name="SelectableItemTheme">
<item name="colorControlHighlight">#color/purple_500</item>
<item name="colorControlActivated">#color/purple_700</item>
</style>

RatingBar with pink background when holding

My RatingBar is pretty regular, when selected appears like this
But when touching (and holding) them, all unrated stars are pink, like this
Why does this happen?
The xml:
<RatingBar
android:id="#+id/ratingBarSchedulesRatingTour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:numStars="5"
android:progressTint="#color/yellow_star"
android:secondaryProgressTint="#color/yellow_star"
android:stepSize="1" />
#color/yellow_star is on colors.xml as #F1CD1E
You can use android:progressBackgroundTint attribute on RatingBar to override background color:
android:progressBackgroundTint="#ABABAB"
Create Style and color what you want (press/normal)
<style name="RatingBar" parent="Theme.AppCompat">
<item name="colorControlNormal">#F1CD1E</item>
<item name="colorControlActivated">#F1CD1E</item>
</style>
<RatingBar
android:id="#+id/ratingBarSchedulesRatingTour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:numStars="5"
android:progressTint="#F1CD1E"
android:theme="#style/RatingBar"
android:secondaryProgressTint="#F1CD1E"
android:stepSize="1" />

Change TextInputLayout focused & unfocused hint color programmatically

I wanted to change the color of hint in TEXT INPUT LAYOUT same when it is in focused or unfocused state.i have two TEXT INPUT LAYOUT fields.Both fields are same color.But it in focused state color appears but in an unfocused state the default grey color appears.i want to keep the color color of hint same in both focused and unfocused state.
<com.example.viveka.snipeid.CustomTextInputLayout
android:id="#+id/input_layout_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
app:errorEnabled="true"
>
<EditText
android:id="#+id/editEmail"
android:layout_width="match_parent"
android:layout_height="40dp"
android:hint="email / snipe id"
android:digits="abcdefghijklmnopqrstuvwxyz.#0123456789"
android:textAllCaps="false"
android:textSize="12sp"
android:layout_marginLeft="-4dp"
android:textColor="#color/lightgray"
android:textColorHint="#color/primary"/>
</com.example.viveka.snipeid.CustomTextInputLayout>
Expected image
what i got
i need to change both fields as same color..
you can simply do that by using the material TextInputLayout and add textColorHint , hintTextColor attributes , this works perfectly
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="#color/gray"
app:hintTextColor="#color/gray"
>
You can do like this.
android:textColorHint="#FF0000" was EditText's hint color.
If you want the text color as well as the hint color.
You can change android:textColor="#FF0000" in the EditText.
You can add app:errorTextAppearance="#style/text_in_layout_error_hint_Style" to change the error text color.
<com.example.viveka.snipeid.CustomTextInputLayout
android:id="#+id/input_layout_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:textColorHint="#FF0000"
app:errorTextAppearance="#style/text_in_layout_error_hint_Style"
app:hintTextAppearance="#style/text_in_layout_hint_Style"
app:errorEnabled="true">
<EditText
android:id="#+id/editEmail"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="-4dp"
android:digits="abcdefghijklmnopqrstuvwxyz.#0123456789"
android:hint="email / snipe id"
android:textAllCaps="false"
android:textColor="#FF0000"
android:textColorHint="#color/primary"
android:textSize="12sp"/>
</com.example.viveka.snipeid.CustomTextInputLayout>
The LEFT-TOP hint color depended on app:hintTextAppearance="#style/text_in_layout_hint_Style".
And the style code:
<style name="text_in_layout_hint_Style">
<item name="android:textColor">#FF0000</item>
<item name="android:textSize">12sp</item>
</style>
Add error text style
<style name="text_in_layout_error_hint_Style">
<item name="android:textColor">#00ff00</item>
<item name="android:textSize">12sp</item>
</style>
like this:
Hope to help you.
Create a selector_text_input_layout_hint_color.xml (for example)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/colorWhenFocus" android:state_focused="true"/>
<item android:color="#color/colorWhenNotFocus" android:state_focused="false"/>
</selector>
Set in the Text Input Layout with the next attribute:
android:textColorHint="#color/selector_text_input_layout_hint_color"
Thanks to: https://medium.com/#fast3r/this-is-brilliant-martin-thank-you-very-much-6c4a43a65df4
That's all. It works for me ;)
In new material theming, the hint color is a tinted version of the colorOnSurface attribute when unfocused.
When focused it is the colorPrimary

How to set the colors of Android small RatingBar

I am trying to set a custom color for the small progressbar with this code:
<style name="RatingBar" parent="Theme.AppCompat">
<item name="colorControlNormal">#color/gold_yellow</item>
<item name="colorControlActivated">#color/light_grey</item>
</style>
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="true"
android:rating="3.3"
android:theme="#style/RatingBar"
android:id="#+id/go_rating"
style="#android:style/Widget.Holo.Light.RatingBar.Small"/>
The problem with this is this: the stars are small quite alright but they are blue. But If I remove style="#android:style/Widget.Holo.Light.RatingBar.Small then the color becomes golden yellow but it becomes big.
Please how do I set custom colors for the stars and at the same time make it small?
Use style="?attr/ratingBarStyleSmall" style:
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="true"
android:rating="3.3"
android:theme="#style/RatingBar"
android:id="#+id/go_rating"
style="?attr/ratingBarStyleSmall"/>
see also: https://stackoverflow.com/a/3173594/5183999

How can I change bottom line colour based on EditText state?

I have an EditText which I set its state to editable=false on first load like this:
<EditText
android:id="#+id/text_personalPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:background="#drawable/editbox_profile_style"
android:textColorHint="#4d4d4d"
android:padding="10dp"
android:layout_marginTop="5dp"
android:editable="false"
android:layout_weight="1"
android:hint="#string/user_telephone" />
When I touch a button just at its right, its state changes to editable=true.
I want to hide the bottom line of the EditText to transparent when editable=false, and I want to show the regular line when editable=true.
How can I achieve this?
with appcompat v7
overriding the value for colorControlActivated, colorControlHighlight and colorControlNormal
<style name="Theme.App" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">#ffffff</item>
<item name="colorControlActivated">#e6e6e6</item>
<item name="colorControlHighlight">#e6e6e6</item>
</style>

Categories

Resources