【问题标题】:change the spinner title bar style更改微调器标题栏样式
【发布时间】:2012-10-08 16:59:03
【问题描述】:

如何更改微调器标题栏样式。

我希望更改以下项目的标题栏:

icon
title textsize,textColor and
background color

我该怎么做?

请帮助我...我已经搜索了谷歌和更多网站。我没有得到任何解决方案。所以请让我知道它的可能。如果可能意味着我如何开发这个????请解释我。

编辑:

这是我的代码:

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

 }

【问题讨论】:

  • 你可以在这里添加你的源代码,以便我们可以帮助你
  • @S Varun 请阅读我更新的问题并为此提供解决方案。
  • 试试 Suraj Bajaj 回答它可能对你有用

标签: java android title android-spinner custom-titlebar


【解决方案1】:

您必须创建 CustomSpinner,

要这样做,请尝试以下方式,它对我很有效

第 1 步:创建自定义 Spinner 类

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

        }  

     }

第 2 步:调用此适配器

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

dropdownspinnertext 的 XML

我正在使用 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"
/>

对于 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"/>

希望对你有帮助

【讨论】:

    【解决方案2】:

    使用 Java(代码):

    spinner.setPrompt("Title")

    来自 XML:

    android:prompt="@string/spinner_title

    See this to change style

    【讨论】:

    • 标题没问题。如何更改标题文本颜色、标题文本大小和标题背景颜色
    • 是的。我看到你的代码更新了。你已经在这样做了。让我再看看。
    • 试试这个:stackoverflow.com/a/12914526/1581147 不过我不确定。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-05
    • 2011-03-13
    • 1970-01-01
    • 1970-01-01
    • 2011-12-18
    相关资源
    最近更新 更多