16

新しいスピナーを動的に作成しています。リストの背景色を変更するにはどうすればよいですか?

現在の背景色は濃い灰色です。

2 つのマペット スピナーの背景属性を白に変更すると、次の望ましくない状況が発生します。

2 つのマペット アクティビティで透明にしたいのですが、スピナーを開いたとき (押したとき) だけ、背景を白くしたいです。

スピナーを作成しているコードは次のとおりです。

私はアダプタを作成しています:

    mAdapter = new ArrayAdapter<String>(getApplicationContext(), 
                                     R.layout.spinner, R.id.Language, lang);
    LinearLayout layoutHolder = 
                         (LinearLayout)findViewById(R.id.RegisterFormLayout);
    Spinner spinner = new Spinner(getApplicationContext());
    LayoutParams layParams= new 
                Spinner.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,       
                                         ViewGroup.LayoutParams.WRAP_CONTENT);
    spinner.setLayoutParams(layParams);
    spinner.setAdapter(mAdapter); 
    spinner.setOnItemSelectedListener(new myOnItemSelectedListener());
    if (lang != null)
       spinner.setSelection(lang.intValue());
    spinnerList.add(spinner);
    layoutHolder.addView(spinner);

私の spinner.xml レイアウトは次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" 
android:id="@+id/SpinnerLayout">

<TextView
    android:id="@+id/Language"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="#ffffff"
    android:background="#00ffffff"
    android:padding="5dp" />
</LinearLayout>

なにか提案を?

4

4 に答える 4

24

この要件は、テーマの変更によっては実現できないと思います。Spinner コンストラクターは、レイアウト xml に記述した場合にのみ popupBackground attr に値を割り当てるため、それ以外の場合はデフォルトのテーマ値が使用されます。以下のように

   <Spinner
    android:id="@+id/spinner1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:popupBackground="@android:color/holo_green_dark" />

// ポップアップの背景を変更してみる

于 2013-04-25T09:02:13.480 に答える