簡體   English   中英

強制Android在Webview中始終顯示鍵盤

[英]Force Android to always show keyboard in webview

我正在嘗試將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>

我要尋找的是,一旦我進入聊天室,鍵盤始終保持打開狀態(URL來自聊天開發者網站上的聊天室,所以我的會是一樣的。)

任何想法如何解決這個問題? 請注意,我是Eclipse / Android的新手,因此,通過我的實踐學習,提供一個帶說明的工作示例將對您大有幫助:)

在旁注中,當前聊天的工作方式如下:如果輸入test,則可以使用鍵盤的GO按鈕發送該消息,然后隱藏鍵盤。 或者,您可以鍵入文本,單擊“發送”(在webview中),然后它們隱藏了鍵盤,但未發送,您必須再次單擊“發送”按鈕...如果您問我,這有點煩人:)

謝謝你的時間。

在您的清單活動中使用此功能。希望它有效

android:windowSoftInputMode="stateAlwaysVisible"

或這個

android:windowSoftInputMode="adjustPan|stateAlwaysVisible"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM