[英]Force Android to always show keyboard in webview
I am trying to add webview to my project to have a chatroom available. 我正在尝试将Webview添加到我的项目中以提供一个聊天室。 However, as soon as I enter text into the chat, the keyboard goes bye bye, which is a bit of annoying. 但是,一旦我在聊天室中输入文字,键盘就会再见,这很烦人。 Is there a simple way to force the keyboard to stay open for input. 有没有一种简单的方法可以强制键盘保持打开状态以进行输入。
My Code: 我的代码:
GoChatActivity.java 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);
}
}
My reg.xml in layout is 我在布局中的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>
My AndroidManifest.xml for this activity 我的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>
What I am looking for is that the keyboard always stays open once I am in the chat room (the url is from the chat on the chat developers website, so mine will be the same.) 我要寻找的是,一旦我进入聊天室,键盘始终保持打开状态(URL来自聊天开发者网站上的聊天室,所以我的会是一样的。)
Any idea how to resolve this issue? 任何想法如何解决这个问题? Note, I am new to Eclipse / Android, so a working example with an explanation would help most, as I learn by doing :) 请注意,我是Eclipse / Android的新手,因此,通过我的实践学习,提供一个带说明的工作示例将对您大有帮助:)
On a side note, currently the chat works like this: If you enter test you can send it with the keyboards GO button, then the keyboard hides. 在旁注中,当前聊天的工作方式如下:如果输入test,则可以使用键盘的GO按钮发送该消息,然后隐藏键盘。 Or you can type text, klick send (in webview) then they keyboard hides and it is NOT sent and you have to click the send button again... a bit annoying if you ask me :) 或者,您可以键入文本,单击“发送”(在webview中),然后它们隐藏了键盘,但未发送,您必须再次单击“发送”按钮...如果您问我,这有点烦人:)
Thanks for your time. 谢谢你的时间。
use this in ur manifest activity.hope it works 在您的清单活动中使用此功能。希望它有效
android:windowSoftInputMode="stateAlwaysVisible"
or this 或这个
android:windowSoftInputMode="adjustPan|stateAlwaysVisible"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.