[英]Spinner textSize doesn't change the fontsize in the app
I am using the xml
in my layout
folder to declare my spinners. 我在
layout
文件夹中使用xml
声明微调框。 For example: 例如:
<Spinner
android:id="@+id/foo_spinner"
android:layout_width="0sp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="30sp" />
I load the spinner entries within my code. 我在代码中加载了微调项。 My problem is that the text size isn't affected.
我的问题是文本大小不受影响。 I can put
100sp
there but nothing will happen. 我可以放
100sp
,但是什么也不会发生。 Do I have to change it only after I load the spinner content? 仅在加载微调器内容之后才需要更改它吗? Do I need to do this after every time I update the content?
每次更新内容后都需要这样做吗?
If you want to customize the text size Spinner
item then you will have to use custom layout from Spinner
item. 如果要自定义文本大小的
Spinner
项目,则必须使用Spinner
项目的自定义布局。
Suppose, create an custom TextView
layout for Spinner
item named custom_spinner_item.xml
as follows... 假设为
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" />
Now, use this layout XML to show your spinner items like: 现在,使用此布局XML来显示您的微调项,例如:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.custom_spinner_item, list);
Another thing, you should use dp
or dip
instead of sp
for android:layout_width
attribute and android:textSize
isn't appropriate for Spinner
element. 另一件事,对于
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.