[原创]Spinner 改变字体,颜色等...
来源:互联网 发布:婚恋网络的女嫌疑人图 编辑:程序博客网 时间:2024/05/21 18:30
请各位转载的注明出处.谢谢.
原生的Spring 控件是无法更改字体和颜色的...
从下面的代码可以看出...红色的标注显示使用的是Android默认的布局..代码来自于Apidemo.
1 Spinner s1 = (Spinner) findViewById(R.id.spinner1);
2 ArrayAdapter<CharSequence> adapter= ArrayAdapter.createFromResource(
3 this, R.array.colors, android.R.layout.simple_spinner_item);
4 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
5 s1.setAdapter(adapter);
6 s1.setOnItemSelectedListener(
7 new OnItemSelectedListener() {
8 public void onItemSelected(
9 AdapterView<?> parent, View view,int position,long id) {
10 showToast("Spinner1: position="+ position + " id="+ id);
11 }
12
13 public void onNothingSelected(AdapterView<?> parent) {
14 showToast("Spinner1: unselected");
15 }
16 });
2 ArrayAdapter<CharSequence> adapter= ArrayAdapter.createFromResource(
3 this, R.array.colors, android.R.layout.simple_spinner_item);
4 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
5 s1.setAdapter(adapter);
6 s1.setOnItemSelectedListener(
7 new OnItemSelectedListener() {
8 public void onItemSelected(
9 AdapterView<?> parent, View view,int position,long id) {
10 showToast("Spinner1: position="+ position + " id="+ id);
11 }
12
13 public void onNothingSelected(AdapterView<?> parent) {
14 showToast("Spinner1: unselected");
15 }
16 });
通过查找源码...看到android.R.layout.simple_spinner_dropdown_item.xml
看下面的XML.
1 <?xml version="1.0" encoding="utf-8"?>
2 <!--
3 /* //device/apps/common/assets/res/any/layout/simple_spinner_item.xml
4 **
5 ** Copyright 2008, The Android Open Source Project
6 **
7 ** Licensed under the Apache License, Version 2.0 (the "License");
8 ** you may not use this file except in compliance with the License.
9 ** You may obtain a copy of the License at
10 **
11 ** http://www.apache.org/licenses/LICENSE-2.0
12 **
13 ** Unless required by applicable law or agreed to in writing, software
14 ** distributed under the License is distributed on an "AS IS" BASIS,
15 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ** See the License for the specific language governing permissions and
17 ** limitations under the License.
18 */
19 -->
20 <CheckedTextViewxmlns:android="http://schemas.android.com/apk/res/android"
21 android:id="@android:id/text1"
22 style="?android:attr/spinnerDropDownItemStyle"
23 android:singleLine="true"
24 android:layout_width="fill_parent"
25 android:layout_height="?android:attr/listPreferredItemHeight"
26 android:ellipsize="marquee"/>
2 <!--
3 /* //device/apps/common/assets/res/any/layout/simple_spinner_item.xml
4 **
5 ** Copyright 2008, The Android Open Source Project
6 **
7 ** Licensed under the Apache License, Version 2.0 (the "License");
8 ** you may not use this file except in compliance with the License.
9 ** You may obtain a copy of the License at
10 **
11 ** http://www.apache.org/licenses/LICENSE-2.0
12 **
13 ** Unless required by applicable law or agreed to in writing, software
14 ** distributed under the License is distributed on an "AS IS" BASIS,
15 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ** See the License for the specific language governing permissions and
17 ** limitations under the License.
18 */
19 -->
20 <CheckedTextViewxmlns:android="http://schemas.android.com/apk/res/android"
21 android:id="@android:id/text1"
22 style="?android:attr/spinnerDropDownItemStyle"
23 android:singleLine="true"
24 android:layout_width="fill_parent"
25 android:layout_height="?android:attr/listPreferredItemHeight"
26 android:ellipsize="marquee"/>
里面实际上是一个CheckedTextView,而CheckedTextView,又继承自TextView.所以我们可以自己定义一个只有TextView的XML文件...
里面可以随意设置TextView的属性..比如字体...颜色等等.... 然后替换adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);的xml...这样就能改变字体之类的属性了...
至此...相信大家都应该能明白了吧...
- [原创]Spinner 改变字体,颜色等...
- [原创]SPINNER 改变字体,颜色等...
- Spinner 改变字体,颜色等...
- SPINNER 改变字体,颜色等...
- spinner改变字体颜色,大小等
- Spinner改变字体
- 自定义spinner字体颜色
- Spinner背景、字体颜色
- dev grdicontrol 根据条件改变行颜色,字体颜色等
- [原创]可改变单元格字体和背景颜色的CListCtrl
- MFC改变编辑框背景、字体、颜色等
- QT textEdit,lineedit等改变字体颜色方法
- eclipse 中如何改变字体、背景颜色、高亮等
- MFC改变编辑框背景、字体、颜色等
- 改变UITextField placeHolder颜色、字体 、输入光标位置等
- 改变UITextField placeHolder颜色、字体 、输入光标位置等
- 改变UITextField placeHolder颜色、字体 、输入光标位置等
- 改变UITextField placeHolder颜色、字体 、输入光标位置等
- java编程思想 学习笔记 equals 与==
- CentOS 5.x上配置JBoss6.X步骤图解教程
- PostgreSQL与MySQL比较
- 条件显示FeatureLayer要素内容
- 纯JavaScrip图表插件——Highcharts
- [原创]Spinner 改变字体,颜色等...
- 本月空闲下来的第一篇博文--论证数据库中索引的重要性以及模糊查询的低效率
- 记录移动开发的资料
- 任意长度大数 高精度四则运算
- [美化] 1%电量、高级关机菜单修改教程
- 在代码中如何减小 spinner 字体的大小?
- 随波而逝的巨星Jim Gray
- maven基本命令
- Linux内核完全剖析0.12(一)