我将EditText的InputType设置为TYPE_NULL:
editText.setInputType(InputType.TYPE_NULL);
我可以将它设置为TYPE_NULL,它有效!但是如果我想将InputType设置为其他东西,比如TYPE_CLASS_TEXT,它就不起作用了!
如何在代码中动态更改它?喜欢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");
}
}
});
}
}
标签:android,android-edittext,null,input-type-file
来源: https://codeday.me/bug/20190825/1719606.html