I have to dynamically change Typefaceof EditText, and also process the help text if Typeface has changed. I just do the following:
<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>
And my code snippet looks like this:
EditText textBox = (EditText) findViewById(R.id.textBox);
Typeface tf = Typeface.createFromAsset(this, "myfont.ttf");
textBox.setTypeface(tf);
String hintText = textBox.getHint().toString();
String newText = processText(hintText);
textBox.setHint(newText);
When I launched the program, I received the following exception:
java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String java.lang.CharSequence.toString()' on a null object reference
Please help me solve this problem.
source
share