Reputation: 358
So my webview is not working with the select element. In other words when I click the select element on any page it does not show the menu.
html select element example:
<select>
<option>test</option>
<option>testing it</option>
<option>bla bla bla</option>
</select>
java creating my webview:
NestedWebView nwv = new NestedWebView(activity.getApplicationContext());
nwv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
registerForContextMenu(nwv);
nwv.setWebViewClient(new webViewClient());
nwv.setWebChromeClient(new webChromeClient(nwv));
nwv.addJavascriptInterface(new JSInterface(), "drconsole");
nwv.getSettings().setJavaScriptEnabled(true);
nwv.getSettings().setLoadWithOverviewMode(true);
nwv.getSettings().setUseWideViewPort(true);
nwv.getSettings().setSupportZoom(true);
nwv.getSettings().setBuiltInZoomControls(true);
nwv.getSettings().setDisplayZoomControls(false);
nwv.getSettings().setAllowFileAccess(true);
nwv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
nwv.getSettings().setSupportMultipleWindows(true);
nwv.getSettings().setGeolocationEnabled(true);
nwv.setDrawingCacheEnabled(true);
nwv.getSettings().setPluginState(WebSettings.PluginState.ON);
nwv.loadUrl(url);
nwv.setDownloadListener(new DownloadListener(){
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength){
try{
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
String filename = new URL(url).getFile();
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename.substring(filename.lastIndexOf('/')+1));
DownloadManager dm = (DownloadManager) activity.getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
Toast toast = new Toast(activity.getApplicationContext());
View iview = activity.getLayoutInflater().inflate(R.layout.activity_toast, (ViewGroup) activity.findViewById(R.id.toast_root));
TextView text = (TextView) iview.findViewById(R.id.text);
text.setText("Downloading File");
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(iview);
toast.show();
}catch(Exception e){
e.printStackTrace();
}
}
});
my build.gradle
android {
compileSdkVersion 27
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "deeproot.theanarch.org.deeproot"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
I also have almost everything possible for webviewclient and webchromeclient used. Please comment before you vote on my question.
Upvotes: 3
Views: 3937
Reputation: 358
To Fix this bug is that the webview MUST be initialized with the activity not the application context.
This line:
NestedWebView nwv = new NestedWebView(activity.getApplicationContext());
Must be:
NestedWebView nwv = new NestedWebView(activity);
Upvotes: 6
Reputation: 75
You have to extend the WebViewClient, there is a detailed introduction how to do it https://stackoverflow.com/a/49350716/4159854
Upvotes: -1