我想让String-array中的每个项目都有不同的颜色,我想在spinner中显示它们:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="horizontal">
<Spinner
android:id="@+id/alldata"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:entries="@array/alldata"
android:gravity="center"></Spinner>
</LinearLayout>
答案 0 :(得分:0)
使用它来显示微调器上的特定颜色
//StringArray
<string-array name="payment_list">
<item><![CDATA[<font color="#ff8519">alldata</font>]]></item>
<item><![CDATA[<font color="#85ff94">Furniture</font>]]></item>
<item><![CDATA[<font color="#fff123">Appliance</font>]]></item>
<item><![CDATA[<font color="#fff123">School Tools</font>]]></item>
</string-array>
活动/片段
final Spinner spinner1 = (Spinner) findViewById(R.id.transaction_spinner);
String[] array = getResources().getStringArray(R.array.payment_list);
Spanned[] spannedStrings = new Spanned[3];
for(int i=0; i<array.length; i++){
spannedStrings[i] = Html.fromHtml(array[i]);
}
spinner1.setAdapter(new ArrayAdapter<CharSequence>(MainActivity.this,
R.layout.support_simple_spinner_dropdown_item,spannedStrings));