简体   繁体   中英

Hover behavior not taking effect in Android Webview

I have a webpage that has several css hover styles, using both the :hover pseudo selector and via the cursor property. If I load this webpage in an embedded WebView on an Android device that has a mouse (eg Chromebooks), the CSS hover rules are not recognized. The cursor is always the same and the hover highlighting never triggers. Is there any way to enable this behavior?

Java:

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate( Bundle savedInstanceState ) {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main );

        WebView webview = (WebView) findViewById( R.id.webview );
        webview.loadUrl( "http://localserver/test.html" );
    }
}

XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="world.of.testapp.MainActivity">

    <WebView
        android:id="@+id/webview"
        android:layout_width="368dp"
        android:layout_height="495dp"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp" />
</android.support.constraint.ConstraintLayout>

test.html:

<html>
  <head>
    <style>
      #a:hover {
        color: red;
      }

      #b {
        cursor: pointer;
      }
    </style>
  </head>
  <body>
    <div id="a">HELLO</div>
    <div id="b">WORLD</div>
  </body>
</head>

似乎这是Android中尚未实现的功能,即将发布: https : //bugs.chromium.org/p/chromium/issues/detail?id=584424

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