EditText可以使用:TextView.setEnabled(true)来设置为可编辑,其实很简单,写在这里以便以后自己查看。
Button设置可用性:setVisibility(View.VISIBLE),这样就设置为可用了。其中参数是一个int型
以后有其他的控件的设置,可以再进行补充。
见如下代码的21,22行:
1 protected void onCreate(Bundle savedInstanceState) { 2 super.onCreate(savedInstanceState); 3 setTheme(android.R.style.Theme_Black); 4 //Return the intent that started this activity. 5 final Intent intent = getIntent(); 6 //获取intent里到底是绑定action字符串,下面用来判断是点了哪个按钮 7 final String action = intent.getAction(); 8 setContentView(R.layout.mydiaryedit);//添加对应的layout 9 System.out.println("intent.getAction():"+intent.getAction());10 myToast("intent.getAction():"+intent.getAction());11 TextView wyl_tv = (TextView) findViewById(R.id.wyl_txt);12 wyl_tv.setText("intent.getAction():"+intent.getAction()+";\n\n"13 + " URI uri = intent.getData(): "+intent.getData()+";\n\n MyDiaryEdit.java的intent:"+getIntent());14 mTitleText = (EditText) findViewById(R.id.title);15 mBodyText = (EditText) findViewById(R.id.body);16 17 confirmButton = (Button) findViewById(R.id.confirm);18 modifyButton = (Button) findViewById(R.id.modified);19 20 if (EDIT_TEXT_ACTION.equals(action)) {21 /*22 * EDIT_TEXT_ACTION.equals(action),EDIT_TEXT_ACTION就是前一个23 * 页面中intent.setAction的时候设置的哪个字符串,这样就能够判断是不是点了新增日记的按钮了24 */25 mState = STATE_EDIT;26 mTitleText.setEnabled(false);//设置为不可编辑27 mBodyText.setEnabled(false);//设置不可编辑28 modifyButton.setVisibility(View.VISIBLE);//把修改按钮设置为可见29 mUri = intent.getData();30 mCursor = managedQuery(mUri, projection, null, null, null);31 mCursor.moveToFirst();32 String title = mCursor.getString(1);33 mTitleText.setTextKeepState(title);34 String body = mCursor.getString(2);35 mBodyText.setTextKeepState(body);36 37 setResult(RESULT_OK, new Intent(MyDiaryEdit.EDIT_TEXT_ACTION, mUri));38 setTitle("编辑日记");39 } else if (INSERT_TEXT_ACTION.equals(action)) {40 mState = STATE_INSERT;41 setTitle("新建日记");42 } else {43 44 Log.e(TAG, "no such action error");45 MyDiaryEdit.this.finish();46 47 return;48 }49 50 confirmButton.setOnClickListener(new MyBtnOnClickListen());51 modifyButton.setOnClickListener(new MyBtnOnClickListen());52 53 }
Button的setVisibility(int visibility),设置可用性,官方文档里的说明如下:
void . . .setVisibility(int visibility)
Set the enabled state of this view.
- Parameters:
- visibility One of
VISIBLE
,INVISIBLE
, orGONE
. @attr - ref android.R.styleable#View_visibility
由此可见,其他的View应该也可以使用该方法。
Button标签有个andorid:visibility属性,如果设置为 invisible,那么就默认为不可见。如下:
18
1 modifyButton.setVisibility(View.VISIBLE);//把修改按钮设置为可见