Android 从XML定制微调器
我有一个从字符串数组加载数据的微调器,我想从XML布局而不是Java代码(正如我在许多示例中看到的)对其进行定制Android 从XML定制微调器,android,android-layout,android-spinner,Android,Android Layout,Android Spinner,我有一个从字符串数组加载数据的微调器,我想从XML布局而不是Java代码(正如我在许多示例中看到的)对其进行定制 是否可以从XML更改文本颜色和微调器样式?可以,下面是如何添加微调器布局 item_spinner.xml <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@a
是否可以从XML更改文本颜色和微调器样式?可以,下面是如何添加微调器布局 item_spinner.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="@dimen/small_margin"
android:background="@color/white"
android:ellipsize="marquee"
android:paddingLeft="@dimen/margin_small"
android:singleLine="true"
android:text="--Select--"
android:textColor="@color/text_title"
/>
并像这样在适配器中使用
ArrayAdapter<String> itemsAdapter =
new ArrayAdapter<String>(this,R.layout.item_spinner, items);
ArrayAdapter项Adapter=
新阵列适配器(此,R.layout.item_微调器,items);
你就完了。自定义但保持textView id与适配器在其上设置文本的方式相同。这将有助于更改文本颜色和样式检查是否有帮助