4
我必须动态改变Typeface
的EditText
,并在字体改变时处理提示文本。我简单地做如下:以编程方式在android中获取提示文本值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: Attempt to invoke interface method 'java.lang.String java.lang.CharSequence.toString()' on a null object reference
请帮助我解决这个问题。
你试过getParent()。getHint()吗?您可能正在使用设计支持库。 – AnixPasBesoin
@Anix PasBeson在EditText中没有getParent()。getHint()。 –
张贴您的xml plz。 – AnixPasBesoin