2015-07-22 32 views
1

我想在创建活动时显示键盘。但键盘没有显示。即使使用editText.requestFocus也不显示键盘

我使用Nexus_5_API_22_x86模拟器

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_ex); 
    EditText editText = (EditText) findViewById(R.id.ex); 
    InputMethodManager imm = (InputMethodManager)this.getSystemService(Service.INPUT_METHOD_SERVICE); 
    imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); 
    editText.requestFocus(); 
} 

可能是什么问题?

我也试过它没有在启动时显示键盘:

@Override 
public void onResume() { 
    super.onResume(); // Always call the superclass method first 

    TimerTask tt = new TimerTask() { 

     @Override 
     public void run() { 
      EditText editText = (EditText) findViewById(R.id.ex); 
      editText.requestFocus(); 
      InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
      imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); 
     } 
    }; 

    final Timer timer = new Timer(); 
    timer.schedule(tt, 200); 

} 
+0

什么是模拟器的配置?你有“键盘支持”活动吗? – JDenais

回答

1

我没有和例子来看看这和线为我工作是这个打开

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); 

并关闭

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); 

编辑

我试图在三星Galaxy S4(真实设备)

在模拟器我的例子键盘不会显示

0

你试过设置requestFocus()方法第一次像这样

editText.requestFocus(); 
InputMethodManager imm = (InputMethodManager)this.getSystemService(Service.INPUT_METHOD_SERVICE); 
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); 
+0

是的...我尝试过......没有工作....我也试过onResume与一个计时器....没有工作 – GJain