简体   繁体   中英

Force Android to always show keyboard in webview

I am trying to add webview to my project to have a chatroom available. 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

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

<?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

    <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.)

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 :)

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. 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 :)

Thanks for your time.

use this in ur manifest activity.hope it works

android:windowSoftInputMode="stateAlwaysVisible"

or this

android:windowSoftInputMode="adjustPan|stateAlwaysVisible"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM