简体   繁体   English

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

[英]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属性应使用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