So I'm setting a button's background doing this:
b.setBackgroundResource(R.drawable.custom_button1);
How do I programmatically set it back to the default (boring grey) Android button? Is there a R.android.boring_grey resource identifier I can reference without recreating those states myself? Couldn't seem to find it. Maybe my Googling skills are failing me.
Oh and by the way I tried this:
b.setBackgroundResource(0);
And the button actually disappeared (blended with black background?).
Have you tried this?
android.R.drawable.btn_default;
first get the default background of Button b; using
Drawable d = b.getBackground();
then set another background of your choice
b.setBackgroundResource(R.drawable.custom_button1);
if you need default background again use this
b.setBackgroundDrawable(d);
Use this
b.tr.setBackgroundDrawable(null);
I did it by
this.setBackgroundResource(android.R.drawable.btn_default);
try
button.setBackgroundResourses(R.drawable.yourimage);
it will set the default background of buttons.
and you can read more default properties of android widgets from given link:
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/styles.xml
Drawable for "modern" button in XML is #android:drawable/btn_default_material
It does not exist in android.R.drawable for some reason.
EDIT: it's private, so don't use it.
Related
I need to change button style from "contained" to "outlined" at runtime.
For now the only way I've found to create an outlined button is to set its style to ?attr/materialButtonOutlinedStyle.
Unfortunately I haven't found a way to change the style at runtime, is it possible?
Is there any way to get this effect?
As a view with text inside, it should have "setTextAppearance" function. It's not the ideal option but may help. Also can be useful to look on https://github.com/airbnb/paris.
I am trying to use the default Theme.holo button drawable for Android but I cannot find the standard one that's used whenever you create a button. I have tried checking everywhere in the sdk\platforms\android-19\data\res\ but to no avail. Any help searching for it would be appreciated. Thanks in advance!
It looks like the one on the left here, but is mildy transparent.:
The drawables for your theme are located in:
platforms/android-*/data/res/drawable-*
See this link
As it says you can find the drawables in
yourandroidsdkrootfolderpath\platforms\android-11\data\res\drawable
(ex:D:\android\platforms\android-11\data\res\drawable)
EDIT
Correct path
yourandroidsdkrootfolderpath\platforms\android-8\data\res\drawable-mdpi
I want to change my button background at RUNTIME
I know how to add a custom background to a button, but
How can I change it to borderlessButtonStyle?
in the xml was easy, I used:
style="?android:attr/borderlessButtonStyle")
How can I switch back to the default background? The following is not what I want (apperantly it is not the default used in Jelly Bean)
changeableButton.setBackgroundResource(android.R.drawable.btn_default);
Thanks for your help
I actually found a solution
You can save the initial background of your button in a Drawable object
Drawable d = button.getBackground();
Now you can modify your button's background as you wish
button.setBackgroundResource(R.drawable.custom_button);
Than you can modify it back
button.setBackgroundDrawable(d);
does this work?
changeableButton.setBackground(null);
There is a simple answer to this problem:
button.setBackgroundResource(R.drawable.backround);
you can also change back to your default backround by using an if statement and repeating the above statement by just changing the "backround" resource to your default resource.
Btw thanks for A2A.
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
I am somewhat of a new android developer and have a question regarding changing the background dynamically at runtime.
What I want to do is set a background color in a LinearLayout Tag, and later change that background color in my activity class. This code below is not working. Am I missing something or is this the wrong approach for trying to change the background color in a linear layout
LinearLayout lv = (LinearLayout)findViewById(R.id.ChoiceLayout);
lv.setBackgroundColor(0x000080);
Thanks in advance
First thing I've noticed is that your color has ALPHA = 0x00. Which makes it transparent. Try changing to
lv.setBackgroundColor(0xFF000080);
AFAIK, that should work fine. Use hierarchyviewer to try to diagnose what is going wrong.
already answered in another post , unfortunately i don't know that link but know the solution.
use
lv.setBackgroungColor(GetResources().getColor(int color));