Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从XML定制微调器_Android_Android Layout_Android Spinner - Fatal编程技术网

Android 从XML定制微调器

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布局而不是Java代码(正如我在许多示例中看到的)对其进行定制


是否可以从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与适配器在其上设置文本的方式相同。

这将有助于更改文本颜色和样式检查是否有帮助