BackgroundTint produces a weird color in Android - android

Okay... I tried asking this before, but I dont think I explained it well...
I have a button in Android. The button's default color is #999999 (Holo Light), with it's opacity (I think its 40%), on my background color, it ends up calculating to #575757. The background is #303030.
I would like to apply a BackgroundTint to this button. The color I am applying as the tint is #F68800. However, when I apply this tint, the color of the button does not show as #F68800, it instead calculates to #7c501a. I assume this has to do with the Holo Light button being slightly transparent...
What can I do to get the button's final color to show up as #F68800?
I have tried using android:backgroundTintMode="src_over", but that ends up ignoring the style of the button and the 9 patch.

As you suspect, the original alpha is your problem. You need it to be ignored in order to get your "clear" tint color. However, ignoring the original alpha also means that you lose the shape/style that the button gets from its 9-patch (as you've already noticed).
Naturally, this makes for an impossible situation -- you cannot both ignore and use the original alpha.
If this is really important, I think your best bet may be to just copy the original 9-patch into your project (don't forget all the dpi variants and various states), make the main button area an opaque white, and make your tinted buttons use that background instead.
The easier alternative is to switch to the Material themes (perhaps the support library version in order to get backwards compatibility). The support library also enables backgroundTint on older Android versions.

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.

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.

Get button-clicked color of theme

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"

Should I set my TextView colours if my background colour is not set?

When I comes to specifying colours for an application, I recently came across #android:color. Is it recommended to try to always use predefined system colors?
I changed the colours of some of my labels to something brighter, so that they'll stand out against the black background. But then I start to wonder... would themes/skins (not familiar with those) and such cause the default background colour to be something other than black?
If so... what's the proper way to deal with colouring one's widgets?
(Disclaimer: I don't know Android. This is general UI design advice.)
If you set the foreground color, you should change the background color as well. Otherwise, if someone's background is set to something wacky, your labels could wind up invisible -- or at the least, hard to see -- and you'll have defeated the purpose of using different colors.
I'd recommend you leave the colors as they are, unless you can change the background color as well. Perhaps using a bold font or something would be a better idea.
You've got 2 options:
1) define explicitly fore/background colors of all of your elements
2) use only default colors, so when the user change its theme, everything will change accordingly. Personally, i prefer this way, but be careful if your UI's got some images
Be consistent, so you'll avoid issues when users change its themes. choose one and back to work!

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