如题。网上多半是 spinner在选择选项之后做出响应事件以改变字体颜色,那么在选择之前,要更改其默认显示的颜色该怎么改呢?
adapter= new ArrayAdapter<String>(abcd_Activity.this,
android.R.layout.simple_spinner_item, array);
//注意第二个参数 android.R.layout.simple_spinner_item
spinner.setAdapter(adapter);
spinner.setVisibility(View.VISIBLE); //设置可见
spinner.setSelection(0, true);//设置默认显示
上面的代码中,adapter= new ArrayAdapter<String>(abcd_Activity.this, android.R.layout.simple_spinner_item, array); 第二个参数就是设置样式的布局文件。点进去看其源码。
<?xml version="1.0" encoding="utf-8"?>
<!--
/* //device/apps/common/assets/res/any/layout/simple_spinner_item.xml
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->
<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"/>
其实就是TextView的样式。 要想改变 spinner的默认字体颜色,就只需要在里面添加 textColor 属性就可以了。但是,因为这是安卓自带的样式,你添加了也没用。所以这时候就需要自己新建一个xml了, 很简单复制他的改个名字, 记住名字要全部小写。放进layout目录下就可以了。
adapter_xianghao = new ArrayAdapter<String>(Rapid_inspection_Activity.this,
R.layout.my_text_view, xiang_hao);
<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:textColor="@color/colorWhite"
android:textAlignment="inherit"/>
记得修改你想要的修改的属性,比如textColor。