【发布时间】:2013-10-05 14:58:14
【问题描述】:
我正在尝试更改通过 ArrayAdapter 创建的 AutocompleteTextView 建议的字体
Wadapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line);
我查找了文件 simple_dropdown_item_1line.xml 并将其传输到我的布局文件夹。这是它的内容:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/dropDownItemStyle"
android:textAppearance="?android:attr/textAppearanceLargePopupMenu"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:ellipsize="marquee" />
这样可以轻松更改建议的大小等。但是不能从 xml 更改字体类型(基本字体选项除外),这需要从代码中完成。我尝试使用这行代码:
TextView scroll= (TextView) findViewById(android.R.id.text1);
Typeface type = Typeface.createFromAsset(getAssets(),"Typewriter.ttf");
scroll.setTypeface(type);
但最后一行给了我 NullPointerException。有人知道如何进行吗?
【问题讨论】:
-
哪一行抛出
NPE? -
最后一个,也就是textview好像是null...
标签: android fonts android-arrayadapter autocompletetextview typeface