Get button-clicked color of theme - android

Is there a way, to get the button-clicked colour based on the current theme? The best would be a xml #color that I can use.
I am planning to use this colour for my ImageButtons when pressed.

If you just want to get a specific color one time, you could hold the button down on your device and screenshot it. Then open the image in MS Paint or something to grab the colors used.

I have found an workaround. When you set this as background, the colour is changed automatically by the operating system according to the theme as if it was a button.
android:background="?android:attr/selectableItemBackground"
If you want to use the attribute on pre API 11 devices you can use:
android:background="?attr/selectableItemBackground"

Related

Android - imageView.background.setTint() changes color of background drawable throughout the application

We have an imageView whose background has a vector asset drawable(ic_star.xml). When I change the background tint of this imageView programatically with a custom color like below, it causes to change the color of imageViews on other pages using this vector assset. In other words, whatever color I set last, that color stays on all other screens. I think this function directly affects the vector asset used throughout the application.
binding.imageView.background.setTint(Color.parseColor("#0E8E1D"))}
In addition, when I use android:backgroundTint attribute in XML, this problem does not occur. Other pages are not affected. But since I get the colors from the api, I have to do it programmatically. We do not prefer to use databinding in our project as it increases the build time. That's why I can't handle this with binding expression.
I found a solution when I wanted to look at the effect of the imageView.background.setTint(color : Int) function in a simple app. I wasn't too sure if it was the right solution. backgroundTintList property worked like android:backgroundTint attribute in xml.
binding.imageView.backgroundTintList = ColorStateList.valueOf(Color.parseColor("#0E8E1D"))
You can review my example app in github and try the difference imageView.backgroundTintList and imageView.background.setTint() methods. I'm waiting for your comments.
https://github.com/tugceaktepe/ImageViewTint
Thanks.

selector drawable not working when applying on a button

selector drawable xml not working when applying it to a button on the screen, whenever i change the background of the button to the drawable xml the button is not being pressed when i run the app and it's color doesn't change, when i change the background to a static color it returns to it's normal behavior and is press-able, any solutions?
selector xml
activity xml
I got this error in the past and from what I lean is that From Android Studio 4.1 many of the components started using the Material Components And sets up the default theme to be based on Theme.material components.DayNight.DarkActionBar.
And because of this, any Button elements in a layout get turned into MaterialButton, and MaterialButton that ignores android:background.
In my case, I solved this with -
app:backgroundTint="#null" //just need this
android:background="#drawable/background_button"
and if this does not work for you, you can check this answer here, which I used in the past, hope it's helps.

Android Spinner Color style

Is there a way of changing the color of the Spinner control?
For example, Android 6 will render text with an arrow. I need to change the color of that arrow.
The change should apply to any version of android.
For example, Android 4 has underline with corner triangle. I have seen some approaches where you replace the icon that is being drawn, but that solution would not work for me. I need to change the color of the default icon.
Update
I have found how to apply style on Android Spinner using styles.xml,
<item name="android:spinnerStyle">#style/SpinnerItem</item>
but I cannot find what is the correct style to apply for the icon color to change.
It turns out, there is no nice way of doing this. It is possible to change the images used for the spinner, but then I would need to provide different set of images for each version, and also have conditionals / logic on the android code, to specify which set should be used based on version.

Android, change only clicked color of a button

I would like to change the default orange color that appears when someone press an Android button. I have done many searches but all I found was the use of selectors.
I understand the principle, but I don't want to modify the grey aspect of the normal button (not pressed). But using selectors force to define all characteristics of all aspects (pressed or not).
I don't know how to obtain the default aspect of buttons in the light theme, so can anyone tell me where I can find the original parameters of the light theme or at least give me another means to simply change the color of the button when clicked?
You can copy the Android's selector into your project, the one that Android sets it by default to buttons, and modify only the state when the button is pressed by just changing one single drawable.
You could find the file in \android-sdk\platforms\android-10\data\res\drawable\btn_default.xml
Sorry bro...........
i guess only selector will help you......
You must go with selector.....
and selector are reusable xmls you can use in all buttons.....:)
You can refer below link.
:)
http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
I tried to find a solution to this problem, but did not succeed.
Maybe this will help:
How to modify the default button state in Android without affecting the pressed and selected states?
Standard Android Button with a different color

Coloring Default Buttons - color filter only on unfocused state

I want to buttons of different colors, but I want to do so while using
the default button background resource in order to preserve the
onfocus and onclick states. This is because I want to use the default
highlight color of the OS for my app, which is NOT always orange (HTC
Sense makes it green).
I found that adding a color filter to the button's background drawable
works great (in this case, blue):
myButton.getBackground().setColorFilter(Color.parseColor(this.getString
(R.color.button_blue)), Mode.MULTIPLY);
BUT, when the button is focused or clicked, it turns a nasty
orange_blue because it mixes the color filter with the orange of the
background drawable.
I want to ONLY set this color filter for the unfocused/unclicked nine-
patch drawable within the default button's statelistdrawable.
I'm not sure how else to do this.
I see a similar solution here:
Fixed: "Android: Detecting focus/pressed color"...
but I have some concerns with that solution, mainly what if the OS
changes the graphic of the default button? Since the normal unfocused/
unpressed graphic is now hardcoded into the app, it would break the
flow.
Maybe can someone comment on whether it would be good or bad practice
to hardcode the default graphic into the app? What are the chances of
the OS completely changing the graphic?
Any help please? Thanks very much!!

Categories

Resources