我有一个可加载Web应用程序的android Webview应用程序。在android 8以外的所有android版本中,它都可以正常工作。问题是该应用有很多输入,其中datalist为下拉列表。在装有android 8的手机中,下拉菜单不起作用。它只是一个普通的输入框。
package com.example.webviewapp;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.content.MutableContextWrapper;
import android.os.Build;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.view.View;
public class MainActivity extends AppCompatActivity {
private WebView mywebView;
String webURL="http://tstcrushmate.codinoz.com";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mywebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings= mywebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mywebView.setWebViewClient(new WebViewClient());
mywebView.clearCache(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR_MR1) {
mywebView.getSettings().setDomStorageEnabled(true);
}
//improve webView performance
mywebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
mywebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR_MR1) {
mywebView.getSettings().setAppCacheEnabled(true);
}
mywebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR_MR1) {
webSettings.setDomStorageEnabled(true);
}
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
webSettings.setUseWideViewPort(true);
webSettings.setSavePassword(true);
webSettings.setSaveFormData(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
webSettings.setEnableSmoothTransition(true);
}
if (savedInstanceState == null)
{
mywebView.loadUrl(webURL);
}
}
@Override
protected void onSaveInstanceState(Bundle outState )
{
super.onSaveInstanceState(outState);
mywebView.saveState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState)
{
super.onRestoreInstanceState(savedInstanceState);
mywebView.restoreState(savedInstanceState);
}
@Override
public void onBackPressed() {
if(mywebView.canGoBack())
{
mywebView.goBack();
}
else
{
super.onBackPressed();
}
}
}
class InternalContext {
private static InternalContext instance;
private MutableContextWrapper mutableContext;
protected static InternalContext getInstance() {
if (instance == null) {
instance = new InternalContext();
}
return instance;
}
protected void setBaseContext(Context context) {
mutableContext.setBaseContext(context.getApplicationContext());
}
protected MutableContextWrapper getMutableContext() {
return mutableContext;
}
}
上面的代码代表了我的mainactivity.java 我的android manifest.xml在下面
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.webviewapp"
tools:ignore="ExtraText,MissingVersion"
android:versionName="1.0"
android:versionCode="1">
<uses-permission android:name="android.permission.INTERNET"
android:hardwareAccelerated="true" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="Accord CrushMate"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning,RtlEnabled"
tools:targetApi="donut">
<activity android:name=".MainActivity"
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我不擅长android编程或java。请帮忙。谢谢