setBackgroundDrawable is not changing the LayoutBackground - android

I have seen several instances of this question on here and the provided solutions dont seem to work.
My goal : Update the background of my LinearLayout depending on what color i get back from a database query.
What I have so far:
if(teamc=="black"){
drawable = this.getResources().getDrawable(R.drawable.blackbackground);
Toast.makeText(TeamActivity.this,teamc, Toast.LENGTH_LONG).show();
teamColor.setBackgroundDrawable(drawable);
}
Team color is defined as
teamColor = (LinearLayout) findViewById(R.id.teamcolor);
What is happening is that the Toast is appearing just fine but the background is not changing.
Any help would be appreciated.

Are you sure that that toast is showing and not other toast? Because you try to check a String if it's equal to another String by using == operator and that is wrong.
You have to use .equals() method to make a comparison between two Objects.

It is really strange if Toast is working but background is not changing.
Try using teamc.equals("black"){}
or
teamColor.setBackgroundResource(R.drawable.blackbackground);

try to make directly teamColor.setBackgroundResource(R.drawable.blackbackground);

call the invalidate() of the LinearLayout using teamColor object after set the background
teamColor.invalidate();

In my application I use a WebView to display a web page, when the page is scale fits well but now are whites spaces on each side of the page, I can change the background to black color??

Related

How do I dim the background for an android spinner?

I want to dim the background around a spinner dropdown, but I cannot find any way to accomplish this.
Research has uncovered the possibility of placing a fullsize framelayout between the activity and the spinner dropdown, and setting a background colour and alpha value on this.
However, I cannot find anyway to determine when the actual dropdown is getting displayed so that I can insert this frame.
Am I looking at this problem the wrong way? Surely there must be a way to dim the background behind a spinner dropdown.
I think you should be able to use the Spinner.OnClickListener. When this is called, you can dim the screen with your framelayout
I ended up using something very similar to this answer in a related question. https://stackoverflow.com/a/18636385
Along with a RelativeLayout in the activity to act as a dimming mask.

How custom seterror() background and icon

A lot of posts talk about this probleme, but nobody give the solution to custom the background of seterror() of EditText. It is really possible?
I have this :http://www.romito.fr/public/images/edittext-before.png
->And i would like that : http://www.romito.fr/public/images/edittext-after.png
I already tried all solutions found on stackoverflow... (like How to display input errors in popup? for example)
Thanks
You can try putting your image on the edittext background in the XML code and then do this:
if(some error)
YOUR_IMAGE.setVisibility(View.VISBILE);
else
YOUR_IMAGE.setVisibility(View.GONE);

Fill with Color on Android

I have an image which include 10 boxes on my image view. When I click the one of boxes I want to change color of box (fill with color). How do I do that? Should I use Surface View or something else?
Update:
I found a solution. But if I use AsyncTask the code does not work. If I use a normal class the code works. I do not know why but I think problem is related with invalidate().

How to identify an imageview drawable?

There's an ImageView in my app with a drawable that can be changed by the user and a black TextView over it. If the user changes this image to one with a black background, he won't be able to see the text.
How can I identify if the image resource is R.drawable.imageA so I can set the text a different color?
I thought about setting a tag for the ImageView, but then I would have to set it for each option, when there's only two options I care about.
I tried:
if (imageview.getDrawable.equals(R.drawable.imageA)) {
textView.setText(Color.WHITE);
}
Also tried with getResource, but neither worked.
Aside from WebnetMobile.com's answer, you could just have a variable related to which image is currently displayed.
IE. When it starts up:
boolean isImageA = true;
And then change that to false when the event to change the background is triggered. All you have to do then is check whether it's true or false.
You can't. You need to store it yourself on side and use for your comparisons, or extend ImageView and embed that functionality inside (i.e. by adding getDrawableId())
Are you going to provide the user with a Dialog box / selection mechanism where the user gets to pick the image ?
If the answer to the above is Yes, then this is the place where you should be able to capture this decision within your application, and then modify the color of the TextView .
If the answer to 1 is no, then how does the user change the Image within your application ?
In your case, you may also be able to use reflection to achieve your goal. For example, take a look at this thread -> Android, getting resource ID from string?
Added later:
For a truly generalized solution, you may want to inspect the ImageView itself, to determine the optimal color to display. This has been demonstrated in this thread:
Automatically change text color to assure readability

How I can change the Background in runtime in Android?

I want to make a simple program with 2 Radiobutton (rd1 and rd2), what can change background to picture s1, or s2, depend on what was selected. How I can make it? I tried background.setBackground (background is my RadioGroup's name), but it didn't work.
try this for changing android wallpaper.
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/SetWallpaperActivity.html
and if you want change the background for the current activity means
if your layout is lay means then,
lay.BackgroundDrawable(R.drawable.abc);
in onClick listenerof ur radio button
sure it will help you dude..let me know what happened...
Thank you.

Categories

Resources