Android dynamic background - android

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));

Related

How to change EditText look programmatically?

I want to change default edittext look(Image:Look which i need to change) from box like look(Image:Look whic i need)...
This must be done programmatically,...I dont know how to do this...please help me
Edit : Sorry typed the title wrong
Edit:Why this is not a useful question??
who voted this question down...anybody please fix this by voting up...I cant post questions
I would create a 9patch image and then set the background drawable programmatically. Please look at this tutorial and see if it's of any help.
http://wptrafficanalyzer.in/blog/changing-background-color-and-border-color-of-an-edittext-widget-using-state-list-in-android/
EDIT: doing a little more research I've found that you can get the desired look&feel by just creating a shape in drawable.xml file. You can find some samples here: http://letustech.wordpress.com/2012/09/16/customedittext/ ... then just call setBackgroundResource on the EditText to set it programmatically.
Create a 9 patch drawble and use that as your background.Call setBackDrawable() to use it

Android change the List view theme at runtime

Can anyone give me some idea or code if possible regarding how to change the Theme of Listview ( like the back ground color, text color, icons etc) by clicking a button for example at runtime?
I saw an example here android dynamically change style at runtime.
I want to know if something similar is possible for List Views?
Thank You.
For changing the Bg color, you can set it dynamically.
mListView.setBackgroundColor(mColor); //doc
For changing the design in your listView, you have to set some variables, then use them in your custom adapter. When you click, you change these variables and call the notifyDataSetChanged() method.
Hope this will help you.
If I understand your question correctly, you want to customize the look and feel of the rows (individually or all) dynamically. If so, using a custom adapter and overriding the getView(...) function will probably work for you.
A quick explanation is available at http://www.mkyong.com/android/android-listview-example/
Hope this helps.

Android Gallery Background

I have followed a gallery tutorial and have it working fine, but the problem that I need help solving is that I want to change the background colour of the gallery. If I just use:
setBackgroundColor(Color.BLACK);
then it messes up and I lose the border also. I want to keep the border, but change the colour from the default grey. I've also tried using different resources such as:
R.styleable.gallery1_android_colorBackground
but that also does not work. Does anyone have any idea how to solve this?
Cheers
In your getView() from your ImageAdapteradd the following attribute:
imageView.setBackgroundColor(Color.BLACK);
Hope this help.

How to get a Button's background back to default (programmatically)?

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.

changing EditText

When I change the layout_height of an EditText field in Android, the nice looking gradient becomes a hard gray line as you can see here:
Is there a way to either fix or disable this gradient?
thx
Ben
You may want to just give it a different background, using a nine-patch presumably. (I have noticed this too and don't like it either! :) )

Categories

Resources