我需要动态更改EditText
的字体,并且在字体更改时处理提示文本。我按照以下步骤进行 :
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_textBox"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/textBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_date" />
</android.support.design.widget.TextInputLayout>
我的代码片段如下:
EditText textBox = (EditText) findViewById(R.id.textBox);
Typeface tf = Typeface.createFromAsset(this, "myfont.ttf");
textBox.setTypeface(tf);
String hintText = textBox.getHint().toString(); //Got NullPointerException here....
String newText = processText(hintText); //This will process the hint text;
textBox.setHint(newText);
当我运行程序时,出现了以下异常:
java.lang.NullPointerException: 尝试在空对象引用上调用接口方法'java.lang.String java.lang.CharSequence.toString()'
请帮我解决这个问题。