2

こんにちは、下のスピナーからリスト項目を選択しているときに、デフォルトのオレンジ色を赤に変更したいのは私のコードです

テキストをスピナーリストの中央に配置し、ラジオボタンを選択して削除するには、カスタムアダプターを作成しました

   ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.range, R.layout.middle_text_spinner);
spBAFirst.setAdapter(adapter);

現在、middle_text_spinner の xml ファイルは以下にあります...

<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/spinnerItemStyle"
android:singleLine="true" 
android:layout_width="fill_parent"
android:textColor="@color/tabDark"
android:layout_height="wrap_content"
android:gravity="center" />

スピナーの画像が下にあります

スピナー

まず、この中間テキストの色をではなく白に変更したい

ただし、リストを開くと、すべてのテキストは黒と白の背景である必要がありますが、一部の電話テキストでは白になります

ここに画像の説明を入力

リストを選択しているときに、デフォルトのオレンジ色に変更したい

Google で検索しましたが、選択中に色を変更できません

私はlistSelectorで試しましたが、それを実行して使用することはできません以下も私のコードです

これは描画可能なフォルダー btn_red_color.xml ファイルにあります

 <?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:state_enabled="false" android:state_focused="true"
    android:drawable="@color/red" />
   <item android:state_pressed="true"
    android:drawable="@color/red" />
   <item android:state_focused="true"
    android:drawable="@color/red" />
</selector>

この値をスピナーlistSelectorに設定します

 <Spinner
  android:id="@+id/spBAFirst"
   style="@style/my_cust_text"
   android:layout_width="100dp"
   android:layout_height="35dp"
   android:background="@drawable/blue_button"
   android:listSelector="@drawable/btn_red_color" />

my_cust_text スタイルは

  <style name="my_cust_text">
    <item name="android:layout_width">0dp</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:ellipsize">marquee</item>
    <item name="android:lines">1</item>
    <item name="android:maxLines">1</item>
    <item name="android:layout_weight">1</item>
    <item name="android:entries">@+array/range</item>
    <item name="android:layout_marginLeft">-3dip</item>
    <item name="android:layout_marginRight">-3dip</item>
    <item name="android:gravity">center</item>
</style>    

しかし、それは機能していません:(どんな体でも私を助けてください

4

2 に答える 2

3

この方法で解決策を見つけました。作業の 90% を確実に行うことができます :)赤の強調表示された色を表示できます

ここに画像の説明を入力

MySpinnerAdapter という CustomAdapter を作成します...

  MySpinnerAdapter adapter = new MySpinnerAdapter(MySettings.this);
  spBAFirst.setAdapter(adapter);


 static class ViewHolder {
    TextView text;
}

private class MySpinnerAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    String[] array;

    public MySpinnerAdapter(Context context) {
        mInflater = LayoutInflater.from(context);
        array = getResources().getStringArray(R.array.range);
    }

    @Override
    public int getCount() {
        return array.length;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    // A view to hold each row in the list
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.middle_text_spinner, null);
            holder = new ViewHolder();
            holder.text = (TextView) convertView.findViewById(R.id.spinnerText);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.text.setText(array[position]);
        convertView.setBackgroundResource(R.drawable.btn_red_color);
        return convertView;
    }
}

このファイルを描画可能なフォルダー btn_red_color.xml に入れます

  <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_enabled="false" android:state_focused="true"
    android:drawable="@color/white" />
  <item android:state_pressed="true"
    android:drawable="@color/red" />
  <item android:state_focused="true"
    android:drawable="@color/red" />
</selector>

Spinnerのxmlファイルはこんな感じ

  <Spinner
                    android:id="@+id/spBAThird"
                    style="@style/my_cust_text"
                    android:layout_width="100dp"
                    android:layout_height="35dp"
                    android:background="@drawable/blue_button"
                    android:cacheColorHint="@color/red"
                    android:textColor="@color/white" />

Middle_text_spinner.xml ファイルは以下のとおりです

   <?xml version="1.0" encoding="utf-8"?>
 <TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinnerText"
style="?android:attr/spinnerItemStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:singleLine="true"
android:textColor="@color/tabDark" />

楽しんで :)

于 2012-10-09T05:25:42.300 に答える
0

このスレッドをチェックアウト: カスタムセレクターを介したAndroidListViewSelectorカラー ListViewアイテムの背景 http://www.geekmind.net/2009/10/android-custom-listview-selector.html

于 2012-10-08T07:40:29.383 に答える