Typeface
を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>
そして、私のコードスニペットは以下の通りです:
java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String java.lang.CharSequence.toString()' on a null object reference
てください:
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);
私はプログラムをラントとき、私は次の例外を得ましたこの問題を解決するのに役立ちます。
getParent()。getHint()を試したことがありますか?あなたはおそらくデザインサポートlibを使用しています。 – AnixPasBesoin
@Anix PasBeson EditTextにはgetParent()。getHint()はありません。 –
あなたのXML plzを投稿してください。 – AnixPasBesoin