以下是代码
package com.phonegap.mobilemone;
import com.phonegap.DroidGap;
import android.view.KeyEvent;
import android.content.Context;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebView;
public class KeyBoard
{
private WebView mAppView;
private DroidGap mGap;
public KeyBoard(DroidGap gap, WebView view)
{
mAppView = view;
mGap = gap;
}
public void showKeyBoard()
{
InputMethodManager mgr = (InputMethodManager)mGap.getSystemService(Context.INPUT_METHOD_SERVICE);
// only will trigger it if no physical keyboard is open
mgr.showSoftInput(mAppView, InputMethodManager.SHOW_IMPLICIT);
((InputMethodManager)mGap.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(mAppView, 0);
}
public void hideKeyBoard()
{
InputMethodManager mgr = (InputMethodManager) mGap.getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(mAppView.getWindowToken(), 0);
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK)
{
if (mAppView.canGoBack())
{
mAppView.goBack();
return true;
}
}
return super.onKeyDown(keyCode, event);
}
}
答案 0 :(得分:1)
使用PhoneGap,您可以使用“backbutton”事件并将所有代码保存在JavaScript中。请参阅http://docs.phonegap.com/en/1.4.1/phonegap_events_events.md.html#backbutton
中的PhoneGap文档中的示例