Question

I am using the customised spinner. Every item of spiner will be TextView with Height and width set to wrap_Content property. I have also set the background colour of both the spiner and the textview to same colour code in hexadecimal.

My problem is- colour is visible only upto the area in which text is written and the remaining area is visible as white .

Can anyone tell me what property needs to be set so that no white portion will be visible. Spinner Image

Below is layout for each spinner item -

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00ffff"
android:textsize="14sp"
 >

Spinner item is described in main layout as

    <Spinner android:id="@+id/spiner"
    android:background="#00ffff"
    android:spinnerMode="dropdown"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    />

Can anyone suggest what needs to be done to set the background colour properly. I have attached the image showing the problem area as well

Was it helpful?

Solution 2

Change this :

android:layout_width="wrap_content"

to this :

android:layout_width="match_parent"

In your TextView

OTHER TIPS

Try this:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00ffff"
android:textsize="14sp"
>

The change is:

android:layout_width="match_parent"

Progammatically :

spinner.setPopupBackgroundResource(R.drawable.yourcolor);

For custom spinner,

have a style , Say bg.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:state_pressed="true">
        <shape android:shape="rectangle">
            <solid android:color="#FFFFFF"/>
        </shape>
    </item>
    <item 
        android:state_selected="true">
        <shape android:shape="rectangle">
            <solid android:color="#FFAA00"/>
        </shape>
    </item>
</selector>

In your code,

sp1 = (Spinner)findViewById(R.id.spinner1);

 sp1.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                sp1.setBackgroundResource(R.drawable.bg);
                return true;
            }
        });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top