change the spinner title bar style

2020-03-31 07:43发布

How can i change the spinner title bar style.

enter image description here

I wish to change the title bar for the following items:

icon
title textsize,textColor and
background color

How can i do this?

please help me...i have searched google and more sites.am not getting any solution for this.so please let me know its possible.if possible means how can i develop this????please explain me.

EDIT:

This is my code:

 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            R.layout.row, R.id.country, list);
    spinner.setPrompt("Choose a Status");
  //  spinner.setTextColor("#FF0000");
    spinner.setAdapter(adapter);
    adapter.notifyDataSetChanged();
    spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());

 }

2条回答
别忘想泡老子
2楼-- · 2020-03-31 08:15

Using Java (Code):

spinner.setPrompt("Title")

OR

From XML:

android:prompt="@string/spinner_title

See this to change style

查看更多
▲ chillily
3楼-- · 2020-03-31 08:23

You have to create CustomSpinner,

To do so try this following way, it works well for me

Step 1: Create Custom Spinner Class

    class CustomSpinnerAdapter extends CursorAdapter {
        LayoutInflater mInflater;

        private int cocktailname; 

        CustomSpinnerAdapter(Context context, Cursor cursor)
        {
            super(context, cursor);
            mInflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);  

          cocktailname = cursor.getColumnIndex(YourDatabase.CK_NAME);  

        }

        @Override
        public View newDropDownView (Context context, Cursor cursor, ViewGroup parent)
        {
             return mInflater.inflate(R.layout.dropdownspinnertext, parent, false); 
        }
        @Override
        public View newView(Context context, Cursor cursor, ViewGroup parent)
        {
            return mInflater.inflate(R.layout.spinnertext, parent, false); 
        }

       @Override
        public void bindView(View row, Context context, Cursor cursor)
        { 
                    //Setting the Value here
            TextView paymentname = (TextView) row.findViewById(R.id.text1);    
            paymentname.setTypeface(textFont);
            String cocktail = cursor.getString(cocktailname);
            paymentname.setText(cocktail); 

        }  

     }

Step 2 : Call this Adapter

  CustomSpinnerAdapter custom_spinneradapter = new CustomSpinnerAdapter(this,youcursor);  
  spnListCocktails.setAdapter(custom_spinneradapter); 
  spnListCocktails.setOnItemSelectedListener(this);

Xml for dropdownspinnertext

I am using Checked Dropdown Spinner

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1" 
style="?android:attr/spinnerDropDownItemStyle" 
android:singleLine="true" 
android:layout_width="fill_parent" 
android:layout_height="?android:attr/listPreferredItemHeight"
android:textColor="#FFFFFF"
android:textSize="18sp"
android:background="@drawable/background_image"
/>

For spinnertext.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1" 
style="?android:attr/spinnerItemStyle"
android:singleLine="true" 
android:layout_width="fill_parent"
android:layout_height="wrap_content"  
android:textColor="#FFFFFF" 
android:gravity="center"
android:padding="4dip"
android:layout_marginLeft="10dip"
android:textSize="20sp"/>

Hope it helps

查看更多
登录 后发表回答