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);
        }
    }
});

 

 

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *