原生的Spring 控件是无法更改字体和颜色的...

从下面的代码可以看出...红色的标注显示使用的是Android默认的布局..代码来自于Apidemo.


Spinner s1 = (Spinner) findViewById(R.id.spinner1);       ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(                this, R.array.colors, android.R.layout.simple_spinner_item);        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);        s1.setAdapter(adapter);        s1.setOnItemSelectedListener(                new OnItemSelectedListener() {                    public void onItemSelected(                            AdapterView<?> parent, View view, int position, long id) {                       showToast("Spinner1: position=" + position + " id=" + id);                   }                    public void onNothingSelected(AdapterView<?> parent) {                       showToast("Spinner1: unselected");                   }               });

通过查找源码...看到 android.R.layout.simple_spinner_dropdown_item .xml

看下面的XML

<?xml version="1.0" encoding="utf-8"?> <!-- /* //device/apps/common/assets/res/any/layout/simple_spinner_item.xml ** ** Copyright 2008, 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. */ --> <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@android:id/text1"     style="?android:attr/spinnerDropDownItemStyle"     android:singleLine="true"     android:layout_width="fill_parent"     android:layout_height="?android:attr/listPreferredItemHeight"     android:ellipsize="marquee" />

里面实际上是一个 CheckedTextView,而CheckedTextView,又继承自TextView.所以我们可以自己定义一个只有TextView的XML文件...

里面可以随意设置TextView的属性..比如字体...颜色等等.... 然后替换

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(                this, R.array.colors, android.R.layout.simple_spinner_item);
...这样就能改变字体之类的属性了...

至此...相信大家都应该能明白了吧...


更多相关文章

  1. android 用shape oval属性画圆环变成黑圆形解决办法
  2. android开发之定制标题栏 --- 附源码
  3. 修订:更改listView中item不同状态下的颜色
  4. ScrollView中的组件设置android:layout_height=fill_parent不起
  5. 【转】android ListView几个比较特别的属性
  6. Android(安卓)layer-list的属性和使用详解(阴影、边框效果)
  7. 整理:控件之间的冲突
  8. Android(安卓)LineaerLayout中layout_margin失效不起作用的解决
  9. 应用Style和Theme - Android官方文档中文翻译

随机推荐

  1. Android Handler leak 分析及解决办法
  2. Android当方法总数超过64K时(Android Stu
  3. Android 子线程中更新UI
  4. android ViewPager 使用方法
  5. Unity 3.3增加了对Android的支持
  6. [转] Android keymap file open failed
  7. android浮动搜索框示例
  8. android中调用金山词霸
  9. Android使用JobService实现后台服务
  10. android 访问/assets 和/res目录下文件的