android programatically set Theme to edittext and add drawable background to button - android

I want to programmatically create theme and set it to my Edittext. (I need to set colorControlNormal and colorControlActivated properties). So I guess I need somehow create theme in my code, give those 2 properties to it and than apply it to my Edittext.
Also I need to programatically give button the drawable background. But I need programmatically set color to this drawable stroke.
How can I achieve this in code?

Related

Can't get different state background for MaterialButtonToggleGroup

I'm using Material 3 ButtonToggleGroup, I want to have a different background when a button is selected. However, If I don't add any attributes to my style applied to MaterialButton, I get the background set to colorPrimary when a button is selected but when it's not it's transparent.
When I add a backgroundTint attribute, it always has the same background color, no matter if the button is selected.

Button themes in android studio

How can I change the tint of the buttons within the android studio?
I see some properties when I select the button namely textColor, textColorHighlight, textColorHint and textColorLink
I'm expecting some built-in color themes without me creating custom styles, like standard green colored buttons, and blue secondary buttons.
If you want to change background tint color you can just use:
android:backgroundTint="#android:color/holo_green_light"
or
android:backgroundTint="#android:color/holo_green_dark"
and so on...
you can see other colors using autocomplete.

Icon and Background color together

I need to add both background and an icon and I ought to use background property for both in xml. I cannot set both at the same time so how can I handle this?
You can use the XML for setting the background, and the property "drawableRight" or "drawableLeft" to set the Icon this is the way I do it.

Android UI Button Alpha Property

If I change the Alpha setting on a Button widget to make it translucent, then add a background image to the Button, will the image also be translucent?
Yes. Changing the background property will override any of the styling you have applied to the button and use only that. So if you use a Material-style button that has custom colors, then apply a background property, the "button" will disappear and be only a perfect rectangle of whatever color (including alpha) that you set, with text/drawables on top.

how can I customize and change the background color of spinner in android?

I want to change the background color of spinner and customize spinner. When I used this code in xml android:background="#000000" the color changed but the arrow on the spinner disappears. How can I cuztomize spinner and change the background color without disappearing the arrow?
The arrow is black (or close to it) by default, so it won't show up on a black background. You can change the arrow with the android:dropDownSelector attribute in your XML.
The "background" attribute on a spinner refers to a drawable which contains the background color and the arrow. By specifying a color for the background, there is no longer any arrow. To fix this you need to provide a new 9 patch drawable with the arrow in it.

Categories

Resources