当前位置:操作系统 > 安卓/Android >>

android 弹出输入框,并且默认全选默认值

 其实很简单,把selectall放在show后面就行了


 

final EditText input = new EditText(this); 
input.setText("XXX"); 
new AlertDialog.Builder(this).XXXX.show(); 
input.selectAll() 
         

final EditText input = new EditText(this);
input.setText("XXX");
new AlertDialog.Builder(this).XXXX.show();
input.selectAll()

  


再补充下,如果需要弹出输入对话框,并且全选默认值,并且弹出输入法,结合上面的selectall和下面的代码段即可


 

final AlertDialog dialog = ...; 
 
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() { 
    @Override 
    public void onFocusChange(View v, boolean hasFocus) { 
        if (hasFocus) { 
            dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); 
        } 
    } 
}); 

final AlertDialog dialog = ...;

editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if (hasFocus) {
            dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        }
    }
});

 

 

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,