android更改spinner默认显示的字体颜色。

 如题。网上多半是 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。 

 

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值