[英]Spinner textSize doesn't change the fontsize in the app
我在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
,但是什么也不会发生。 仅在加载微调器内容之后才需要更改它吗? 每次更新内容后都需要这样做吗?
如果要自定义文本大小的Spinner
项目,则必须使用Spinner
项目的自定义布局。
假设为Spinner
项目创建一个名为custom_spinner_item.xml
的自定义TextView
布局,如下所示...
<?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);
另一件事,对于android:layout_width
属性,应使用dp
或dip
而不是sp
,并且android:textSize
不适合Spinner
元素。
<Spinner
android:id="@+id/foo_spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.