标签:
程序进入某个activity直接弹出软键盘,不能直接在OnCreate中设置,必须等View绘制事件完毕才可以弹出,需要用到Timer辅助实现,如果要实现输入的功能,必须让EditText获得焦点。
//应用启动后自动打开输入法 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { InputMethodManager imm = (InputMethodManager)MainActivity.this.getSystemService(INPUT_METHOD_SERVICE); imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); Toast.makeText(MainActivity.this, "show", Toast.LENGTH_SHORT).show(); } }, 1000); //在一秒后打开 }
自动关闭:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editTextField.getWindowToken(), 0);
禁止弹出:
<activity android:name=".ClientSearchViewActivity" android:label="@string/app_name" android:screenOrientation="portrait" android:windowSoftInputMode="adjustUnspecified|stateHidden" android:configChanges="orientation|keyboardHidden"> </activity>
标签:
原文地址:http://www.cnblogs.com/niray/p/4251304.html