当用键盘导航时,JellyBean Webview将自动聚焦html元素,并且无法禁用它

时间:2012-11-23 04:48:12

标签: android android-webview

我遇到JellyBean的问题,每当我用键盘导航时,它会自动聚焦我的超链接和输入的html元素。它创造了一个我无法用css隐藏的蓝色高光。

* {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);  
} 

即使我为每个用于禁用焦点的html元素设置了z-index:-1,但是当我使用键盘导航时,JellyBean仍会自动对焦每个元素。

这是我的HTML代码:

<html>
<head>
    <title></title>
</head>
<body>
    <a tabIndex="-1" href="http://www.yahoo.com">yahoo</a>
    <a tabIndex="-1" href="http://www.google.com">google</a>
    <a tabIndex="-1" href="http://www.msn.com">msn</a><br/>
    <input type="button" name="" tabIndex="-1" value="yahoo">
    <input type="button" name="" tabIndex="-1" value="google">
    <input type="button" name="" tabIndex="-1" value="msn">
</body>
</html>

这是我的webview配置:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<WebView
    android:id="@+id/webView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:focusable="false" />

</RelativeLayout>

这是我的活动:

package com.example.tony;
import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;


public class WebActivity extends Activity {
    private WebView mainWebView;
    private WebSettings webSettings;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.web_view);
        mainWebView = (WebView) findViewById(R.id.webView);

        webSettings = mainWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);      
        webSettings.setPluginState(WebSettings.PluginState.ON);      
        mainWebView.setWebChromeClient(new WebChromeClient());
        mainWebView.setScrollBarStyle(WebView.SCROLLBAR_POSITION_DEFAULT);
        mainWebView.loadUrl("http://192.168.2.145/test/nav.html");
    }

    @TargetApi(16)
    public void setURL(){
          webSettings.setAllowUniversalAccessFromFileURLs(true);
    }
}

使用nexus 7和其他一些软糖设备进行测试。有没有一种解决方案可以禁用对html元素级别的关注或禁用键盘导航自动对焦?

0 个答案:

没有答案