android > EditText 控件操作
* EditText 自动换行
<EditText android:layout_width="0dip" android:layout_height="120dip" android:layout_margin="10dip" android:scrollbars="vertical" android:scrollbarAlwaysDrawVerticalTrack="true" android:gravity="top" android:inputType="textCapSentences|textMultiLine" android:textColor="#000000" />
* EditText 密码显示/隐藏
if(pass_show.isChecked()){ //显示明文 pass.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); }else{ //显示密码 pass.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); }
* 监听EditText 发生变化
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); text = (EditText)findViewById(R.id.text); text.addTextChangedListener(textWatcher); } private TextWatcher textWatcher = new TextWatcher() { @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub Log.d("TAG","afterTextChanged--------------->"); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub Log.d("TAG","beforeTextChanged--------------->"); } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { Log.d("TAG","onTextChanged--------------->"); str = text.getText().toString(); try { //if ((heighText.getText().toString())!=null) Integer.parseInt(str); } catch (Exception e) { // TODO: handle exception showDialog(); } } };
* 默认不获取焦点
在EditText 父级 加属性
android:focusable="true" android:focusableInTouchMode="true"
相关推荐
huha 2020-10-16
xfcyhades 2020-11-20
sgafdsg 2020-11-04
Michael 2020-11-03
fengyeezju 2020-10-14
ziyexiaoxiao 2020-10-14
业余架构师 2020-10-09
OuNuo0 2020-09-29
moses 2020-09-22
Angelia 2020-09-11
qinxu 2020-09-10
刘炳昭 2020-09-10
Nostalgiachild 2020-09-07
Nostalgiachild 2020-08-17
leavesC 2020-08-14
一青年 2020-08-13
AndroidAiStudy 2020-08-07
ydc0 2020-07-30
绿豆饼 2020-07-28