当我从第一个活动转到第二个活动时,我正在尝试打开键盘。主活动中有两个按钮 1)如果单击“NotShowKeyboard”按钮,它将在没有键盘的情况下打开 second.java 活动 2)如果单击“ShowKeyboard”按钮,那么它将使用键盘和 EitdText 打开 second.java 活动专注但问题是我不知道该怎么做。我放了一些示例顶部显示键盘,但在“ShowKeyboard”按钮上单击键盘打开并立即消失。
主.java:
NotShowKeyboard.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
}
if (event.getAction() == MotionEvent.ACTION_UP) {
bundle.putBoolean("show", false);
Intent start = new Intent(Main.this, Start.class);
start.putExtras(bundle);
startActivity(start);
}
return false;
}
});
ShowKeyboard.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
}
if (event.getAction() == MotionEvent.ACTION_UP) {
bundle.putBoolean("show", true);
Intent start = new Intent(Main.this, Start.class);
start.putExtras(bundle);
startActivity(start);
}
return false;
}
});
二.java:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.start);
i = getIntent();
extras = i.getExtras();
search = (EditText) findViewById(R.id.start_edit);
search.addTextChangedListener(myTextWatcher);
if((extras.getBoolean("show"))==true) {
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
}
//getting all stuff like buttons imageViews etc..
}
当 NotShowButton Clicked 然后这应该打开:
当 ShowButton Clicked 然后这应该打开: