在webview应用程序中点击文本字段不显示软键盘

时间:2014-01-14 07:50:36

标签: android webview android-softkeyboard

在我的webview应用程序中,网站上有一些文本字段,但点击它并没有显示软键盘。一些灰色的部分出现在显示屏的下方,看起来像键盘正在隐藏behing。请帮助我解决这个问题。

WebActivity.java

package com.example.samworkshops;



import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class WebActivity extends Activity {
    public WebView webview;


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
         webview = (WebView) findViewById(R.id.webview);
        webview.setWebViewClient(new WebViewClient());
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setUseWideViewPort(true);
        webview.getSettings().setLoadWithOverviewMode(true);
        webview.loadUrl("http://app.samworkshops.org");

    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // Check if the key event was the Back button and if there's history
        if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
            webview.goBack();
            return true;
        }
        // If it wasn't the Back key or there's no web page history, bubble up to the default
        // system behavior (probably exit the activity)
        return super.onKeyDown(keyCode, event);
    }
}

1 个答案:

答案 0 :(得分:0)

你可以这样做,请看这个更新的答案

webview.requestFocus(View.FOCUS_DOWN);
webview.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_UP:

                v.requestFocusFromTouch(); 

            break;
        }
        return false;
    }
});

请访问 http://code.google.com/p/android/issues/detail?id=7189