【问题标题】:Spinner textSize doesn't change the fontsize in the app微调器文本大小不会更改应用程序中的字体大小
【发布时间】:2014-04-02 23:21:35
【问题描述】:

我使用layout 文件夹中的xml 来声明我的微调器。例如:

<Spinner
    android:id="@+id/foo_spinner"
    android:layout_width="0sp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textSize="30sp" />

我在我的代码中加载微调器条目。我的问题是文本大小不受影响。我可以把100sp 放在那里,但什么都不会发生。只有在加载微调器内容后才需要更改它吗?每次更新内容后都需要这样做吗?

【问题讨论】:

标签: android spinner text-size


【解决方案1】:

如果您想自定义 Spinner 项目的文本大小,则必须使用来自 Spinner 项目的自定义布局。

假设,为Spinner 项目创建一个自定义TextView 布局,名为custom_spinner_item.xml,如下所示...

<?xml version="1.0" encoding="utf-8"?>
<TextView  
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:textSize="30sp" />

现在,使用此布局 XML 来显示您的微调器项目,例如:

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

另一件事,您应该使用dpdip 而不是sp 作为android:layout_width 属性,而android:textSize 不适合Spinner 元素。

<Spinner
    android:id="@+id/foo_spinner"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1" />

【讨论】:

  • 谢谢。有没有办法在代码开头设置样式而不是每次更新微调器时都更新它?我会经常这样做。
猜你喜欢
  • 2013-05-17
  • 1970-01-01
  • 1970-01-01
  • 2012-12-21
  • 2011-07-13
  • 2019-09-06
  • 1970-01-01
  • 2018-09-26
  • 1970-01-01
相关资源
最近更新 更多