How to avoid the ugly "boxes" when child views in a View has another color than the background (stateful drawables for example)

I have a simple ListView and on that ListView I have placed a number of custom defined Views. The CustomView has ImageView and two TextViews.

The CustomView also has a "stateful drawable" as background, so that the background image (a 9-patch) changes if you press the Row in the ListView. When pressing the Row, the background image changes to a Red-ish thing.

The problem is that when the background changes from the default greyish, all the Views in the CustomView (ImageView and TextViews) still have their greyish background and thus creates very ugly greay boxes on top of the now redish background.

What is the best way to solve that problem? I hoped that such things were handled automatically (as it is done in for example .NET), but I was wrong it seems.

Asked by: Miranda948 | Posted: 24-01-2022

Answer 1

I got it =)

You can use the color "transparent"


Set the Views with that color, and its all good =)

Answered by: Chloe264 | Posted: 25-02-2022

Similar questions

android - Background drawables define view size

For the sake of clarity, this question has been edited significantly. Let's say I have a .png resource of 100x100px: I want to use that image as a background for my TextViews, which size is determined by its content, which is variable at runtime. Especially, I want that image to tile when the T...

android - Shape Drawables on Samsung devices default to black background

So I'm developing using a Samsung Note 2 device and for some reason when I create this drawable <shape xmlns:android="" > <corners android:radius="5dp" /> <stroke android:width="1dp" android:color="@color/grey_light" /> </shape> and apply it as a background to a LinearLayout, it makes the background black,

Android - Dynamic Coloring of Drawables on a Dark Background

Description When attempting to change the color of a drawable that is on top of a dark background, I ran into an issue where the color would be slightly changed. In the image below, you will see that the top view that has a white background has a dark blueish icon color, but the view below which is on top of a dark background has a light blueish color.

How to use Android vector drawables as background for an activity?

I am unable to set a vector drawable xml as background in an Android activity. I tried to set it as background by setting android:background="@drawable/test_background" to the Coordinator layout root of my activity. to the Coordinator layout child Constraint layout to an ImageView child of the ConstraintLayout via app:srcC...

svg - Why drawables I use in my Android app have wrong aspect ratio when used as buttons background

I put some icons into my Android app layout. They have been imported by means of the "new vector asset" command, from svg files of the material design Google collection here: This is the resource xml: <vector xmlns:android="

java - How to set drawables vector asset as my activity background?

I am trying to set vector asset as background but I am getting errors logcat logcat image logcat Caused by: android.view.InflateException: Binary XML file line #18: Binary XML file line #18: Error inflating class ImageView Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class ImageView Caused by: an...

Android drawing - Background caching

Quick question - I'm having control that's extending LinearLayout and I'm overriding it's onPaint method like this @Override protected void onDraw(Canvas canvas) { super.dispatchDraw(canvas); _background.draw(canvas); _object1.draw(canvas); _object2.draw(canvas); _object3.draw(canvas); // etc... } Every 40ms I invoke postInvalidate() in background and onPaint gets called on...

android - how to start activity when the main activity is running in background?

I created an application which enables the user to set whether he wants to receive notification while the application runs in background mode. If the notifications are enabled an activity should be started (the dialog should appear on the screen). I tried to enabled it the following way: @Override public void onProductsResponse(List<Product> products) { this.products = products; mobool...

android - View on press onpress: Change background color on press? How do I show that the View is being pressed?

I have, for the time being, a custom view with a 9-patch image as a border. That custom view is placed three times in a LinearLayout, so it looks like this: +------------------------+ | CustomView | +------------------------+ | CustomView | +------------------------+ | CustomView | +------------------------+ I have attached a click event listener...

android - how to structure my app to run in background

I am new to Android, and I need some advices for start up. I want to build an application, which will show up, when the user gets into some hot situation. By hot situation I mean: the GPS/cell coordinates are in known zone; known Bluetooth device detected; known Wi-Fi network detected; weather info has change; I see something running in backgroun...

audio - Android - how to do background threading properly?

Was wondering if anyone could help me on background threading on Android. I have a piece of code that records from the mic of the device and then plays back what it records through the ear piece(on 1.5). I am trying to run it in a thread but have been unsuccessful in getting it to run as a background thread. Currently it runs and locks up the activity so that all thats happening is the thread is ru...

android - How to set background color of a View

I'm trying to set the background color of a View (in this case a Button). I use this code: // set the background to green v.setBackgroundColor(0x0000FF00 ); v.invalidate(); It causes the Button to disappear from the screen. What am I doing wrong, and what is the correct way to change the background color on any View? Thanks.

Android Widget Text Background

I have an app with a widget but I am having some difficulty with the layout of the widget. The basic idea if the widget should look like an icon and have a little text tag under it like any other icon on the desktop. I found one example which uses an android:background for the TextView and uses a drawable XML: <shape xmlns:android=""> <solid...

How do I change the background of an Android tab widget?

My class extends extends TabActivity TabHost mTabHost = getTabHost(); TabHost.TabSpec tab1 =mTabHost.newTabSpec("tab1"); TabHost.TabSpec tab2 =mTabHost.newTabSpec("tab2"); tab1 .setIndicator("title tab1"); tab2 .setIndicator("title tab2"); mTabHost.addTab(tab1);mTabHost.addTab(tab2); TabHost.setCurrentTab(0 or 1) Can anybody guide me how do I change the background image or color of sel...

android - Set title background color

In my android application I want the standard/basic title bar to change color. To change the text color you have setTitleColor(int color), is there a way to change the background color of the bar?

Run a service in the background forever..? Android

I am doing a Battery Consuming research on the Android phone. I want to run a Battery Check every 10 min till the battery totally dies. I have been having problems to make it work. At my first try, I use a timer in a service class, and schedule the battery check every 10 mins. But soon I found that the service got paused when the screen goes off. Then I try to use AlarmService, I use a alarm call to wake my...

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Android