简体   繁体   中英

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

in android i have a webview that opens fine and i've set it up like this:

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 webview session there is a listview that pops up and i would like to change the background color of just that listview. right now its white and i want it to be grey ? is there a way to enforce this ?

The list item is from the web server . im just displaying a webview. i just pass it a url. i dont have an adapter as i do not own the listview. its on a webpage

its my companies web server so i could pass in javascript if that would help. what i am noticing is on some devices the color is different. sometimes grey sometimes white. not sure whats going on. the other thing i noticed from the photo as you can see, the listview is coming outside of the webview Window. That might hint to me that this is a native dialog being used by the webview perhaps. so would there be a theme element i can set in android ?

在此输入图像描述

I found out how to do this. The dialog is actually a native dialog even though its invoked from the WebView .

So on your WebView you should apply a custom Theme.Dialog and override the dialog style. Lets show how this can be done:

Create a style like this:

Here's 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 your 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"
/>

You can try apply the style in your activity in manifest file instead of your layout xml file.

Inside your AndroidManifest.xml

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

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