【问题标题】:Force Android to always show keyboard in webview强制 Android 始终在 webview 中显示键盘
【发布时间】:2014-11-24 12:08:57
【问题描述】:

我正在尝试将 webview 添加到我的项目中以提供聊天室。但是,一旦我在聊天中输入文字,键盘就会再见,这有点烦人。有没有一种简单的方法可以强制键盘保持打开状态以进行输入。

我的代码:

GoChatActivity.java

package com.test.abc.activity;
import com.test.abc.xx.R;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class GoChatActivity extends Activity {

@SuppressLint("SetJavaScriptEnabled")
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.reg);
    WebView webView = (WebView) findViewById(R.id.webView1);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient());
    webView.loadUrl("http://dev.openflex.net/candy/");
    webView.requestFocus(View.FOCUS_DOWN);
    InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    mgr.showSoftInput(webView, InputMethodManager.SHOW_IMPLICIT);




}


}

我的 reg.xml 布局是

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
    android:layout_width="match_parent"
    android:layout_height="46dip"
    android:background="@drawable/skin_header_bar_bg"
    android:ellipsize="end"
    android:gravity="center"
    android:singleLine="true"
    android:text="Chat Room"
    android:textColor="@color/skin_bar_text"
    android:textSize="19.0sp" />

<com.test.abc.scrollview.BounceScrollView
    android:id="@+id/scrollView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/coversation_bg"
    android:fadingEdge="none"
    android:fillViewport="true"
    android:scrollbarThumbVertical="@drawable/scrollbar_handle_vertical" >

<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

</com.test.abc.scrollview.BounceScrollView>

</LinearLayout>

我的 AndroidManifest.xml 用于此活动

    <activity
        android:name="com.test.abc.activity.GoChatActivity"
        android:alwaysRetainTaskState="true"
        android:configChanges="locale|keyboardHidden|orientation|screenSize"
        android:exported="true"
        android:windowSoftInputMode="stateVisible"
        android:hardwareAccelerated="true"
        android:launchMode="singleTop"
        android:theme="@style/Default.SwipeBack.NoTitleBar"
        >
    </activity>

我正在寻找的是,一旦我进入聊天室,键盘总是保持打开状态(网址来自聊天开发者网站上的聊天,所以我的会是一样的。)

知道如何解决这个问题吗?请注意,我是 Eclipse / Android 的新手,所以一个带有解释的工作示例将最有帮助,因为我通过实践来学习 :)

顺便说一句,目前聊天是这样工作的:如果您输入测试,您可以使用键盘的 GO 按钮发送它,然后键盘隐藏。或者你可以输入文本,点击发送(在 webview 中)然后他们的键盘隐藏并且它没有被发送,你必须再次点击发送按钮......如果你问我有点烦人:)

感谢您的宝贵时间。

【问题讨论】:

    标签: android webview keyboard


    【解决方案1】:

    在你的清单活动中使用它。希望它有效

    android:windowSoftInputMode="stateAlwaysVisible"
    

    或者这个

    android:windowSoftInputMode="adjustPan|stateAlwaysVisible"
    

    【讨论】:

    • Activity 上的 stateAlwaysVisible 看起来对 Webview 完全没有影响。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-29
    • 1970-01-01
    • 2016-11-26
    • 2023-04-01
    • 2013-06-18
    相关资源
    最近更新 更多