Android ImageButton push color - android

I have an ImageButton that I switch the images when pushed. The problem is that the animation tints the button blue when I push the button between my two image switches. How to I prevent that blueish tint from animating? Also, how do you do it programatically and not through the XML.

Well for most use cases, you should be using XML... but lecture aside, the blue background is part of a StateListDrawable that is set by default as your button's background. Defining and setting your own background (via setBackgroundResource(int resId) or similar) should be sufficient to "get rid" of the focused color state.

Related

Drawable color changes, but after changing activity remains

I have a menu, with several buttons and its drawables. This menu is included in 4 activitys.
I am setting the drawable color programmatically:
mDrawable.setColorFilter (0xff0099cc, PorterDuff.Mode.SRC_IN);
The first button by default is enabled, so the color is changed programmatically. When I press another button to go to another activity, the other button changes the color, but the first one remains as if it had activated.
You are not clear about your drawable and so I ll give generic solution to you.
You can just use Drawable.setColorFilter( 0xffff0000, Mode.MULTIPLY ). If you could make the entire image WHITE (FFFFFF) so that when you do PorterDuff.Mode.MULTIPLY, you end up with the correct colors. Note this would not affect the transparent pixels.
For solid images, it is best to use the color filter PorterDuff.Mode.SRC_ATOP because it will overlay the color on top of the source image, allowing you to change the color to the exact color you are looking for.
Let me know, whether it helps.

How to obtain CheckBox background color

I want to highlight a CheckBox by setting a custom color to its background and then fade that color into whatever was the original background color.
The issue is I don't know how to obtain the "colorTo" for ValueAnimator. Does CheckBox even have something that could be called a background? Or is it merely a text next to a tick-box?
The Checkbox is created at runtime, i.e. by calling its constructor. And I only set its text and an onClick handler, I do not set its bg.
Yes it has a background. Since you creating it at run time the background is not set so it is Transparent (Unless defined otherwise in Style).
For highlighting Button momentarily you can set a desired highlight color and animate the color from Highlighted color to Background color or simply animate it to Transparent color -> "#00000000"
P.S: You probably wont need this but to get background color of a view you can do this:
int color;
Drawable background = view.getBackground().mutate();
if (background instanceof ColorDrawable) {
color = ((ColorDrawable)view.getBackground()).getColor();
}
The mutate() will clone your background so if you used this background in multiple places, with the change of background the other backgrounds won't change.

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.

Transparent Tint on Buttons

In my Android app, I'm trying to get buttons to be tinted a certain color (either blue, red or gold). The default button tint is grey. Does anyone know how to change the color of the button so that the transparency remains with it?
I tried using:android:background
but that ditches the transparency completely and makes the button one solid color.
I also tried using:android:#color/transparent
but that ditches the color completely in favor of a fully transparent button. I've looked online for a while and found mostly stuff relating to image buttons. The kind that I'm trying to tint is just the standard Button buttons. I'm also guessing that this can be done mostly just through XML. Is that correct?
You could try and create your own button drawable like so...
Take the button drawable from the Android SDK ([ANDROID_SDK_HOME]/platforms/data/res) and import the drawables into your project. Then create a layer list with the button drawable on the bottom and a semi-transparent color on top.

Getting the Listview default clicked color, depending on the Device

In my android application, I use a listview and some linear layout on wich the user can click.
Of course, I had to set the background of my LinearLayout to a xml file where the stated pressed, selected are defined:
myView.setBackgroundDrawable(
getDrawable(android.R.drawable.list_selector_background));
So no problem I set the drawable to transparent when normal use and orange when clicked.
My only problem is that on the galaxy S and some other customized phone (Sense UI) the color of the listview clicked is blue or green!
So I need to pick this color to set it to the background of my linearlayout.
I don't want to mix orange and blue, or orange and green for my user!
Where can I get this color???
That woule be really helpfull!
Just found the answer:
android:background="#android:drawable/list_selector_background"

Categories

Resources