android button green - android

i would like to have tha default button but not in gray.
I need to change the color green/blue/red.
I would like to do this thanks to xml but also from the code.
I need to have a green button which change the color of all the other button.
It's why i need to change from xml and from the code.

Define you colors in the color resource so it is easier to apply your desired colors via code or xml.

Related

Change color of an image in android

I wonder if there is a way to change the color of my image on the button easily,
my simple example is like this,
CircleButton.setImageResource(android.R.drawable.ic_media_play);
I have a play audio icon (white) and want to change the icon color to red, like this
CircleButton.setImageResource(ColorChange(Red, android.R.drawable.ic_media_play));
What seems to be the easiest way for doing ColorChange() ?
Use ColorFilter to change the button image color. Your button should be ImageButton
Set the image resource to the ImageButton
CircleButton.setImageResource(android.R.drawable.ic_media_play);
And, change the image color when required like this
CircleButton.setColorFilter(getResources().getColor(R.color.any_color));
Refer : http://developer.android.com/reference/android/graphics/drawable/Drawable.html#setColorFilter(android.graphics.ColorFilter)

android change view's background color when state changes

how to use color state list for background?
I know android:background="#drawable/drawable_selector", but android:background="#color/color_selector" will cause exceptions.
but android:background="#FFFFFF" works again, can anyone explains why?
now i want to change a layout's background color(not a drawable) when it's pressed,
how to do it?
dynamically you can change like this. Use this if it is useful for you -
textView.setBackgroundColor(Color.parseColor(getResources().getString(R.string.red)));
put the color in res/values/colors.xml,
like #FFFFFF,
and then create a drawable xml in drawable directory,
,that is ok.

How to use setTextColor for Android Radio Buttons?

I am trying to change the text color of a RadioButton (which is
defined in an xml layout and is in a RadioGroup) on selecting it.
When I change the text color directly in the Eclipse Android Layout
Editor by setting the TextColor property to "#color/red" (which I
defined in strings.xml), it works just fine, but when I try to do this
programmatically during runtime as
myRadioButton.setTextColor(R.color.red);
it only turns the color to grey, not to red as intended.
R.color.red (#color/red) is correctly defined as a hex value
("#FF0000"), but it does turn the text color to red in the
layout editor, but not via a Java command.
if your color.xml is like:
<color name="errorColor">#f00</color>
and then use this code to show it:
myRadioButton.setTextColor(getResources().getColor(R.color.red));
there are some other ways to do so
myRadioButton.setTextColor(Color.RED);
or
myRadioButton.setTextColor(Color.rgb(red, green, blue));
// where red green and blue are the int values
edited if you want to get from resources then use
getResources().getColor(R.color.red) ;

Color change of a button in code not reflecting

I'm trying to change a color of a button in code as below
btn_no5.setTextColor(0x8E35EF);
the above change is not reflecting(purple color), the text is disappearing after execution of above piece of code. But if i use the color in xml its reflecting. So how to change this through java ?
The color you are using is fully transparent. Use 0xFF8E35EF instead. The first byte is the alpha (transparency) channel.
use like this,
btn_no5.setTextColor(Color.parseColor("#8E35EF"));

How to set AutoCompleteTextView drop down background to transparent in Android?

As the subject suggests , how to set the transparent background to AutoCompleteTextView dropdown. I can apply any style to the view(TextView) that dropdown box shows but to make the drop down itself transparent I am not able to do !
Any hints or solution ?
Thanks
set android:popupBackground to #0FFF in xml
Thanks , got what I was looking for ,
I can change background image of dropdown using
setDropDownBackgroundResource();
and set semi-transparent png.
You have two options:
XML Attribute:
android:popupBackground
The background to use for the popup window.
May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".
Java Attribute
setDropDownBackgroundResource
Sets the background of the auto-complete drop-down list.

Categories

Resources