繁体   English   中英

微调框的textSize不会更改应用程序中的字体大小

[英]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属性应使用dpdip而不是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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM