【发布时间】:2013-01-31 07:40:12
【问题描述】:
当我从第一个活动转到第二个活动时,我正在尝试打开键盘。 主要活动中有两个按钮 1)如果单击“NotShowKeyboard”按钮,它将打开没有键盘的 second.java 活动 2) 如果单击 s"ShowKeyboard" 按钮,那么它将打开带有键盘和焦点的 EitdText 的 second.java 活动 但问题是我不知道该怎么做。我放了一些示例顶部显示键盘,但在“ShowKeyboard”按钮上单击键盘打开并立即消失。
Main.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;
}
});
Second.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 时应该会打开:
当 ShowButton Clicked 时应该会打开:
【问题讨论】:
标签: android android-softkeyboard