Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8541135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:45:42+00:00 2026-06-11T11:45:42+00:00

I try to create a Spinner for choosing a color. The color should display

  • 0

I try to create a Spinner for choosing a color. The color should display in the Spinner-header. Here is a screenshot:

Sceenshot

But as you can see, the color don’t fill my 9-patch Spinner background (header). Here is the 9-patch background:

Background

But I don’t understand why…
I implemented a custom ArrayAdapter, here is the code:

spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new MyArrayAdapter(this, R.layout.spinner_row, R.id.textView1, items);
spinner.setAdapter(adapter);

private class MyArrayAdapter extends ArrayAdapter<String>{

    public MyArrayAdapter(Context context, int resource, int textViewResourceId, String[] objects) {
        super(context, resource, textViewResourceId, objects); 
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return getCustomViewSmall(position, convertView, parent);
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        return getCustomView(position, convertView, parent);
    }

    public View getCustomView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = getLayoutInflater();
        View row = inflater.inflate(R.layout.spinner_row, parent, false);
        View v = (View) row.findViewById(R.id.spinnerFrame);
        v.setBackgroundColor(getColor(position));
        return row;
    }

    public View getCustomViewSmall(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = getLayoutInflater();
        View row = inflater.inflate(R.layout.spinner_row_small, parent, false);     
        row.setBackgroundColor(getColor(position));    
        return row;
    }

    private int getColor(int pos) {
        switch(pos) { 
        case 0:
            return colors[0]; // Blue
        case 1:
            return colors[1];  // Purple
        case 2:
            return colors[2];  // Orange
        case 3:
            return colors[3];  // Yellow
        case 4:
            return colors[4];  // Cyan
        }
        return colors[5];
    }
}

And here is the code of the layout:
The spinner_row_small.xml (that is the layout for the header):

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinnerFrameSmall"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</FrameLayout>

The spinner_row.xml (the layout for the rows):

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/FrameLayout1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center"
android:background="@color/white" >

<FrameLayout
    android:id="@+id/spinnerFrame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:layout_marginBottom="1dp"
    android:layout_marginTop="1dp" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />
</FrameLayout>
</FrameLayout>

And the main.xml:

        <Spinner
            android:id="@+id/spinner"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/textview"
            android:spinnerMode="dropdown"      
            android:popupBackground="@drawable/spinner_background"        
            android:layout_marginBottom="30dp" />

I would be very pleased if anybody can help my.
Best regards!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:45:43+00:00Added an answer on June 11, 2026 at 11:45 am

    I don’t see anything wrong in your code but problem with nine patch image is that, only marked space will get enlarged and you will only get the marked space of image in real use. That is why you are getting space on all sides(which is left unmarked). I think nine patch images are useful for simple backgrounds without much color complexity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im try to create a spinner dynamically on press of a button. this is
I try create a map for open ~/.vimrc, but open the ~/.vimrc only when
I try to create styles with first-child and last-child items but I encountered a
I try to create a thread in QT, can declare, create and start it,
I'll try create a controler in towerjs, but I have an error while updating
I try to create an html helper with a control from Telerik but to
I try create method for get the connection string value but without value for
I want to try create something like Zend's Server Pagecache. What I want to
I try to create donate via PayPal button and add custom select with amount.
I try to create my own linux bash script that calls truecrypt for mounting.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.