change the spinner title bar style

和自甴很熟 提交于 2019-12-01 12:07:41

问题


How can i change the spinner title bar style.

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());

 }

回答1:


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




回答2:


Using Java (Code):

spinner.setPrompt("Title")

OR

From XML:

android:prompt="@string/spinner_title

See this to change style



来源:https://stackoverflow.com/questions/12951203/change-the-spinner-title-bar-style

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!