【问题标题】:Android: How to disable keyboard on webview for some specific page?Android:如何在某些特定页面的 webview 上禁用键盘?
【发布时间】:2016-10-05 05:30:32
【问题描述】:

我有一个WebView,它有一个RelativeLayout 父级。 在WebView 中,当我单击某个特定按钮时,它会加载另一个网址。我想禁用该网址上的键盘。以及我在 shouldoverrideurlloading(WebView view , Url Url) 方法中获得的那个网址。

<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"
    android:background="@drawable/background"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    tools:context="com.xenopsi.benchmark.BrowserActivity">

    <WebView
        android:id="@+id/browserView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:scrollbars="none"/>

   </RelativeLayout>

在我做的那个方法上:

relativeLayout.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
webView.setFocusable(false);
webView.setFocusableInTouchMode(true);

但是当我点击该页面的文本字段时,仍然显示键盘。 如果我对onCreate() 活动方法执行相同的代码,它的工作正常,

但我的问题是想在我的页面加载时在 shouldOverrideUrlLoading 方法上禁用它。

【问题讨论】:

  • 参考this答案
  • 我已经尝试过了,所有的东西都在 oncreate 方法中工作,但我想为特定页面执行此操作,当 shouldOverrideUrlLoading 方法检测到我的 url 时。对于其他页面我想显示我的键盘,但不是那个页面。

标签: android android-webview


【解决方案1】:

好吧,当您提到要隐藏特定链接的键盘时,请执行以下操作,

public boolean shouldOverrideUrlLoading(WebView view, String url) {
    Log.e("Loading URL", url);

    view.loadUrl(url);

    if(url.equals(yourUrl)){
        // hide keyboard
    } else {
        // unhide keyboard
    }
    return true;
}

我希望这会有所帮助..

快乐编码..

【讨论】:

    猜你喜欢
    • 2012-07-09
    • 1970-01-01
    • 2021-08-09
    • 2010-11-06
    • 1970-01-01
    • 1970-01-01
    • 2017-12-25
    • 2019-05-27
    • 2015-08-01
    相关资源
    最近更新 更多