android edittext设置内容为空,android – 我将EditText的InputType设置为TYPE_NULL后无法更改...

我将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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值