本文翻译自:How to change spinner text size and text color?

In my Android application, I am using spinner, and I have loaded data from the SQLite database into the spinner, and it's working properly. 在我的Android应用程序中,我正在使用微调器,并且已经将SQLite数据库中的数据加载到微调器中,并且它可以正常工作。 Here is the code for that. 这是代码。

Spinner spinner = (Spinner) this.findViewById(R.id.spinner1);
List<String> list = new ArrayList<String>();
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>  (this,android.R.layout.simple_spinner_item, list);
cursor.moveToFirst();list.add("All Lists");if (cursor.getCount() > 0) {for (int i = 0; i < cursor.getCount(); i++) {keyList[i] = cursor.getString(cursor.getColumnIndex(AndroidOpenDbHelper.KEYWORD));list.add(keyList[i]);cursor.moveToNext();}
}
Database.close();
cursor.close();
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(dataAdapter);

Now I want to change the text color and text size of spinner data. 现在,我想更改微调器数据的文本颜色和文本大小。 I have used following XML lines to my spinner tag on my XML file, but it is not working. 我在XML文件上的Spinner标记中使用了以下XML行,但无法正常工作。

android:textColor="@android:color/white"
android:textSize="11dp"

How can I change the text color and text size of my spinner? 如何更改微调器的文本颜色和大小?


#1楼

参考:https://stackoom.com/question/dlJR/如何更改微调器的文字大小和文字颜色


#2楼

Simple and crisp...: 简单明快...:

private OnItemSelectedListener OnCatSpinnerCL = new AdapterView.OnItemSelectedListener() {public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {((TextView) parent.getChildAt(0)).setTextColor(Color.BLUE);((TextView) parent.getChildAt(0)).setTextSize(5);}public void onNothingSelected(AdapterView<?> parent) {}
};

#3楼

Another variation of Ashraf's solution would be to make sure you're taking into account screen sizes. Ashraf解决方案的另一种形式是确保您考虑到屏幕尺寸。 You'll need to get the spinner in onCreate and set the listener after you set the adapter: 设置适配器后,您需要使旋转器处于onCreate并设置侦听器:

//set your adapter with default or custom spinner cell, then://
serverSpinner.setOnItemSelectedListener(spinnerSelector);
serverSpinner.setSelection(defaultServer);

Then you can start changing the text size of the view that's showing before the spinner is clicked: 然后,您可以开始更改单击微调框之前显示的视图的文本大小:

private AdapterView.OnItemSelectedListener spinnerSelector = new AdapterView.OnItemSelectedListener() {public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {boolean tabletSize = getResources().getBoolean(R.bool.isTablet);boolean largeTablet = getResources().getBoolean(R.bool.isLargeTablet);if (tabletSize) { ((TextView)parent.getChildAt(0)).setTextSize(16); }else if (largeTablet) { ((TextView)parent.getChildAt(0)).setTextSize(18); }else { ((TextView)parent.getChildAt(0)).setTextSize(12); }}public void onNothingSelected(AdapterView<?> parent) {}
};

All you need to do is create layout specific folders like this: 您所需要做的就是创建特定于布局的文件夹,如下所示:

values-sw360dp 值-sw360dp

values-sw600dp 值-sw600dp

values-sw800dp 值-sw800dp

an then add an xml file named "bool.xml" into each of those folders: 然后在每个文件夹中添加一个名为“ bool.xml”的xml文件:

<?xml version="1.0" encoding="utf-8"?>
<resources><bool name="isTablet">false</bool><bool name="isLargeTablet">false</bool>
</resources>

#4楼

If all the spinners may have the same text color for their TextView items, another approach is to use a custom style for spinner dropdown items: 如果所有微调器的TextView项可能具有相同的文本颜色,则另一种方法是对微调器下拉项使用自定义样式:

In res/values/styles.xml : res/values/styles.xml

<resources><style name="AppBaseTheme" parent="android:Theme.Light"></style><style name="AppTheme" parent="AppBaseTheme"><item name="android:spinnerDropDownItemStyle">@style/mySpinnerItemStyle</item></style><style name="mySpinnerItemStyle" parent="@android:style/Widget.Holo.DropDownItem.Spinner"><item name="android:textColor">@color/my_spinner_text_color</item></style>
</resources>

And define your custom color in res/values/colors.xml: 并在res / values / colors.xml中定义您的自定义颜色:

<color name="my_spinner_text_color">#808080</color>

#5楼

Rather than making a custom layout to get a small size and if you want to use Android's internal small size LAYOUT for the spinner, you should use: 除了要使用小尺寸的自定义布局,而且如果要为微调器使用Android内部的小尺寸LAYOUT,您应该使用:

"android.R.layout.simple_gallery_item" instead of "android.R.layout.simple_spinner_item". “ android.R.layout.simple_gallery_item”,而不是“ android.R.layout.simple_spinner_item”。

ArrayAdapter<CharSequence> madaptor = ArrayAdapter.createFromResource(rootView.getContext(),R.array.String_visitor,android.R.layout.simple_gallery_item);

It can reduce the size of spinner's layout. 它可以减小微调器的布局大小。 It's just a simple trick. 这只是一个简单的把戏。

If you want to reduce the size of a drop down list use this: 如果要减小下拉列表的大小,请使用以下命令:

madaptor.setDropDownViewResource(android.R.layout.simple_gallery_item);

#6楼

Simplest: Works for me 最简单:为我工作

TextView spinnerText = (TextView) spinner.getChildAt(0);spinnerText.setTextColor(Color.RED);

如何更改微调器的文字大小和文字颜色?相关推荐

  1. 使用 rem 设置文字大小(文字响应式)

    响应式理念:响应式网页不仅仅是响应不同类型的设备,而且需要响应不同的用户需求.响应式的初衷是为了让信息更好的传递交流,让所有人无障碍的获取信息,同时这也是 Web 的初衷. 一.rem的定义 网页中常 ...

  2. iOS wkWebview调整html文字大小以及文字两端对齐

    1.问题:后台给的HTML标签字符串用wkwebview加载时需要适当增大文字大小以及将文字两端对齐 修改前效果: 修改后效果: 解决方法:文字增大在wk代理方法实现,使用js语句:文本两端对齐使用添 ...

  3. iOS开发:字符串设置指定内容的文字颜色、文字大小、文字字体类型

    在iOS开发过程中,会有一些为了提高APP的视觉效果而设置的特别一点的效果,比如一行文字需要自定义不同的颜色和文字大小,这就用到通过富文本来设置字符串的颜色.大小和文字类型.这篇博文我打算只介绍怎么设 ...

  4. html图片在wps中不显示文字大小,WPS文字插入图片显示不全怎么办 WPS文字插入图片显示不完整的解决方法...

    在wps文字编辑文档时,如果我们在使用时插入图片显示不全,这种情况我们该怎么解决呢?想必有不少的用户遇到过这种问题,下面教程之家网为大家带来WPS文字插入图片显示不完整的解决方法,不知道怎么解决的朋友 ...

  5. Markdown (CSDN) MD编辑器(二)- 文本样式(更改字体、字体大小、字体颜色、加粗、斜体、高亮、删除线)

    目录 1.Markdown现有的文本样式. 2.HTML的font标签-改字体.字体颜色.字体大小. 3.HTML的mark标签-标记文本 4.HTML的strong标签-加粗文本 5.HTML的em ...

  6. TextView使用Html适配文字颜色(color:““)、文字大小(font-size:14px)、文字权重(font-weight:500)

    TextView使用Html适配文字颜色(color:"").文字大小(font-size:14px).文字权重(font-weight:500) TextView中提供了Html ...

  7. maya2016版本后更改界面文字大小方法

    maya更改界面文字大小方法 maya2016~2019版本,可以直接在首选项的interface(界面)里面更改文字显示大小,而且还可以选择书写表达式时打开的是表达式编辑器还是text文本.曾经一度 ...

  8. 更改PDF中的文本框的文字的大小和颜色

    1,点击文本框工具,添加文本框,并输入内容 2,更改PDF中的文本框的文字的大小和颜色 键盘Ctrl+E,将弹出文本属性菜单,此时就可以更改文本的字体.大小和颜色了. 参考:https://jingy ...

  9. jquery easyui datagrid 更改表格标题,行间距和文字大小

    <div id="table"><table id="order"></table> </div>$(" ...

最新文章

  1. 【面试】上中断和下中断
  2. javascript 关键字使用(break continue return) 数组 函数 数组中的冒泡排序(3分钟全部写完)...
  3. World Final 2012
  4. android 访问https服务器
  5. 面试必会系列 - 2.1 MySQL知识点大汇总(基本架构,存储引擎,锁,事务,索引,B+树等等)
  6. 连续子数组的最大和(基于动态规划)
  7. python是什么 自学-这是大多数新手入门之后强烈推荐的python自学入门指南秘笈...
  8. angular乱码_号外!Angular 中文文档已同步翻译至 7.0
  9. 2020年第十七届中国研究生数学建模竞赛赛题+解压码
  10. matlab 三角函数方程,Matlab关于含有三角函数的方程的求解
  11. cad详图怎么画_CAD结构图怎么画?手把手教你CAD结构图的绘制方法
  12. 2022新轻量级PHP解密在线工具源码V1.2版
  13. Linux网络流量监控
  14. 设置计算机关机时间快捷键,电脑怎么设定关机时间?
  15. 案例—考勤后台管理系统需求
  16. Keepalived源码、yum安装-高可用(主备、主主)场景
  17. Java指导书练习题——抽象类
  18. 张艺谋说高仓健:一位古代君子
  19. 怎样P漫画脸?这三个简单方法分享给你
  20. 习题 8.21 用指向指针的指针的方法对n个整数排序并输出。要求将排序单独写成一个函数。n个整数在主函数中输入,最后在主函数中输出。

热门文章

  1. struts2注解总结----@Action和@Result
  2. Android属性 android:focusableInTouchMode
  3. 总结一下对buffer的学习体会
  4. Android之linux基础教学之二 总体架构
  5. 算法---------数组-----------翻转单链表
  6. 算法--------------有效的数独
  7. Gradle 设置本地maven
  8. Android 布局跟着NAVIGATION_BAR 重新布局
  9. 【UIKit】表格自定义单元格(UITableViewCll)
  10. 过滤输入内容中是否含有特殊字符与表情