2013年3月17日
1、EditText隐藏输入的密码
利用EditText作为密码输入是现在许多应用程序会用到的方式,下面是两种设置密码隐藏/可见的方式:
在布局文件中设置其password属性:
import android.app.Activity;import android.os.Bundle;importandroid.text.Editable;importandroid.text.TextWatcher;import android.util.Log;import android.view.Menu;importandroid.widget.EditText;importandroid.widget.TextView; public class MainActivityextends Activity { TextView textView01; EditText editText01; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView01 = (TextView)findViewById(R.id.textView01); editText01 = (EditText)findViewById(R.id.editText); editText01.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, intstart, int before, int count) { Log.i("输入", s +"/" + start + "/" + before + "/" + count); textView01.setText(editText01.getText()); } public void beforeTextChanged(CharSequence s,int start, int count, int after) { Log.i("输入", s +"/" + start + "/" + count); } public void afterTextChanged(Editable s) { Log.i("输入", s +""); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action barif it is present. getMenuInflater().inflate(R.menu.main, menu); return true; }}