Vic*_*tor 12 android webview android-softkeyboard
我在我的Android应用程序中实现了自定义webview.如果我触摸此webview中的输入或文本区域,则软键盘不会显示.我没有在我的webview中覆盖任何touchlisteners,也没有在我的清单中更改任何内容.任何人都可以帮我弄清楚为什么键盘没有显示?
我的布局代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<nl.AEGEE.enschede.android.AEGEEWebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:progressTint="@color/aegee_blue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-6dp"
android:layout_alignParentTop="true" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
小智 16
请尝试将这些行添加到XML文件中的webview中.
android:focusable="true"
android:focusableInTouchMode="true"
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你.
就我而言,除了添加
android:focusable="true"
android:focusableInTouchMode="true"
Run Code Online (Sandbox Code Playgroud)
我还需要子类化 WebView 并添加此方法
@Override
public boolean onCheckIsTextEditor() {
return true;
}
Run Code Online (Sandbox Code Playgroud)
我从这个线程中得到了解决方案,其中提出了许多其他解决方案。
这是整个WebView子类,如果有人想用的话
public class CustomWebView extends WebView {
public CustomWebView(Context context) {
super(context);
init();
}
public CustomWebView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public CustomWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
protected void init() {
setFocusable(true);
setFocusableInTouchMode(true);
}
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
BaseInputConnection baseInputConnection = new BaseInputConnection(this, false);
outAttrs.imeOptions = IME_ACTION_DONE;
outAttrs.inputType = TYPE_CLASS_TEXT;
return baseInputConnection;
}
@Override
public boolean onCheckIsTextEditor() {
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6095 次 |
| 最近记录: |