(1)在layout中,android:hint 標記設置顯示編輯文字的提示字
(2)在layout中,從background改變背景
(3)利用checkbox改變edittext狀態
package COM.TQC.GDD01; import android.app.Activity; import android.os.Bundle; import android.text.method.HideReturnsTransformationMethod; import android.text.method.PasswordTransformationMethod; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.EditText; public class GDD01 extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final CheckBox cb = (CheckBox)findViewById(R.id.mCheck); final EditText et = (EditText)findViewById(R.id.mPassword); cb.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener(){ @Override public void onCheckedChanged(CompoundButton arg0,boolean arg1) { // TODO Auto-generated method stub if(cb.isChecked()) { et.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } else { et.setTransformationMethod(PasswordTransformationMethod.getInstance()); } } }); } }