Android webView - how to change background color in webView dialog?

in android, I have a webview that opens perfectly, and I installed it as follows:

webView= (WebView) findViewById(R.id.webview); webView.setWebChromeClient(new WebChromeClient()); webView.setWebViewClient(new myWebViewClient()); webView.getSettings().setJavaScriptEnabled(true); webView.loadUrl(url); 

but now during the web browsing session a list popup appears and I would like to change the background color of just this View list. its white right now and I want it to be gray? is there any way to provide this?

The list item is located on the web server. im just displaying webview. I just pass url to it. I do not have an adapter, since I do not have a list. him on the web page

its my company’s web server so I can switch to javascript if that helps. what I noticed on some devices, the color is different. sometimes gray sometimes white. not sure what is going on. the other thing i noticed from the photo, as you can see, listview goes beyond the webview window. This may hint to me that this is a native dialog that can be used by web browsing. so will there be a theme element that I can install in android?

enter image description here

+5
source share
2 answers

I learned how to do it. A dialog is actually a native dialog, although it is called from a WebView .

So, on WebView you have to apply the custom Theme.Dialog and override the dialog style. Let's show how this can be done:

Create a style like this:

Here is myStyle.xml

 <resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="MyDialog" parent="@android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item> <item name="android:windowBackground">@color/orange_transparent</item> <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> </style> </resources> 

Then in WebView you can do this:

 <?xml version="1.0" encoding="utf-8"?> <WebView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/webview" style="@style/myStyle" android:layout_width="fill_parent" android:layout_height="fill_parent" /> 
+5
source

You can try applying style to your activity in the manifest file instead of your XML layout file.

Inside your AndroidManifest.xml

 <activity android:name="com.exmaple.YOUR.ACTIVITY" android:screenOrientation="portrait" android:theme="@style/YourCustomStyle"> </activity> 
0
source

Source: https://habr.com/ru/post/1262539/


All Articles