android edittext设置内容为空,android – 我将EditText的InputType设置为TYPE_NULL后无法更改...
我將EditText的InputType設(shè)置為TYPE_NULL:
editText.setInputType(InputType.TYPE_NULL);
我可以將它設(shè)置為TYPE_NULL,它有效!但是如果我想將InputType設(shè)置為其他東西,比如TYPE_CLASS_TEXT,它就不起作用了!
如何在代碼中動態(tài)更改它?喜歡TYPE_NULL,那么再到TYPE_CLASS_TEXT和TYPE_NULL?
解決方法:
// Try this one
**activity_main1.xml**
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
android:id="@+id/txtValue"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:id="@+id/btnClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enable Input" />
MainActivity1
public class MainActivity1 extends Activity {
private Button btnClick;
private TextView txtValue;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main1);
txtValue = (TextView)findViewById(R.id.txtValue);
btnClick = (Button)findViewById(R.id.btnClick);
txtValue.setInputType(InputType.TYPE_NULL);
btnClick.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(txtValue.getInputType()==InputType.TYPE_NULL){
txtValue.setInputType(InputType.TYPE_CLASS_TEXT);
txtValue.invalidate();
btnClick.setText("Disable Input");
}else{
txtValue.setInputType(InputType.TYPE_NULL);
txtValue.invalidate();
btnClick.setText("Enable Input");
}
}
});
}
}
標(biāo)簽:android,android-edittext,null,input-type-file
來源: https://codeday.me/bug/20190825/1719606.html
總結(jié)
以上是生活随笔為你收集整理的android edittext设置内容为空,android – 我将EditText的InputType设置为TYPE_NULL后无法更改...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android 动态矩形条,androi
- 下一篇: p20pro 鸿蒙,后置镜头变液态双摄?