展会信息港展会大全

自定义 Spinner 显示的样式(修改颜色等) 安卓开发教程
来源:互联网   发布日期:2015-10-02 15:55:13   浏览:1911次  

导读:这里指的Spinner显示的样式,并不是指在点击Spinner后弹出的选择框的样式,而是直接显示在屏幕上的那个按钮的样式。我有个项目需要使用Spinner,但使用默认的样式又与现有UI不匹配,需要稍稍改一下。这个样式其实......

这里指的Spinner显示的样式,并不是指在点击Spinner后弹出的选择框的样式,而是直接显示在屏幕上的那个按钮的样式。我有个项目需要使用Spinner,但使用默认的样式又与现有UI不匹配,需要稍稍改一下。

这个样式其实是由适配器指定的,如:

ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,list);

这里指定使用android.R.layout.simple_spinner_item,我们打开这个文件(当然,你要先下载Android源码),发现里面其实就是一个TextView,内容如下:

<?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="fill_parent"

android:layout_height="wrap_content"

android:ellipsize="marquee" />

现在知道怎么做了吧?自己写个xml,加上一个TextView,id也是@android :id/text1,其他的就看你自己需要了。

赞助本站

人工智能实验室

相关热词: 自定义 Spinner

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港