如何更改微调列表项的文字大小和文字颜色?
How to change the text size and text color of spinner list items?
我正在使用一个微调器,其中包含一些 item.I 列表,想要更改 items.I 的文本颜色和文本大小,我正在使用 android 条目来填充 list.Please 找到下面的代码进行说明。
旋转器代码:
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:textColor="#456789"
android:popupBackground="@color/title"
android:background="@drawable/ic_action_overflow"
android:entries="@array/spinnerItems"/>
您需要创建自定义微调项视图。 I.E 这里是 simple_spinner_item.xml 来自 Android:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:textAlignment="inherit"/>
从那里,您需要将该视图传递到您的适配器中。例如:
new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, new String[] {context.getString(R.string.item1), context.getString(R.string.item2)});
我正在使用一个微调器,其中包含一些 item.I 列表,想要更改 items.I 的文本颜色和文本大小,我正在使用 android 条目来填充 list.Please 找到下面的代码进行说明。
旋转器代码:
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:textColor="#456789"
android:popupBackground="@color/title"
android:background="@drawable/ic_action_overflow"
android:entries="@array/spinnerItems"/>
您需要创建自定义微调项视图。 I.E 这里是 simple_spinner_item.xml 来自 Android:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:textAlignment="inherit"/>
从那里,您需要将该视图传递到您的适配器中。例如:
new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, new String[] {context.getString(R.string.item1), context.getString(R.string.item2)});