簡體   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