[英]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.