【发布时间】:2017-07-17 17:52:31
【问题描述】:
我有一个问题,我想在onCreate方法中禁用一个按钮,请分享在onCreate方法中在运行时禁用任何按钮的方法。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_requests_interface);
Intent intent = new Intent(this, AdminPopup.class);
startActivity(intent);
String fName = getIntent().getStringExtra("fName");
TextView tfName = (TextView)findViewById(R.id.fName);
tfName.setText(fName);
String vuEmail = getIntent().getStringExtra("VUEmail");
TextView tEmail = (TextView)findViewById(R.id.vuEmail);
tEmail.setText(vuEmail);
EditText vuEmailTest = (EditText)findViewById(R.id.vuEmail);
String email = vuEmailTest.getText().toString();
String str = email.substring(0,2);
if(str.equals("bc")){
String str2 = email.substring(3,9);
boolean digitsOnly = TextUtils.isDigitsOnly(str2);
if (digitsOnly){
Button accButton = (Button)findViewById(R.id.accButton);
}
}
else{
Button accButton = (Button)findViewById(R.id.accButton);
}
}
【问题讨论】:
-
在布局中将其设置为禁用。因此,当您通过
setContentView()添加它时,您会发现它已被禁用。通过这样做,您将不需要任何额外的代码。除了以后重新启用它。 -
你可以通过xml使用
enbale属性来禁用它。
标签: java android android-layout disabled-control fragment-oncreateview