Android Webview Auto Update Text Color

I have a WebView integrated into my application. The problem I am facing is autocomplete, which appears when WebView recognizes that a value has previously been entered in a text field. Autocomplete text appears white in color. I did not add any functionality to these text fields. The web page is displayed as is. Does anyone know why something like this is happening? Is there any way to set the text color to black?

In the screenshot attached, the user is trying to enter an email in the text box, and a pop-up window with white autocomplete will appear.

The following code shows how I create Webview:

myxml.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id = "@+id/viewFrame" android:background="@color/myColor"> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/rounded_rectangle" android:layout_gravity="center" android:visibility="gone" android:id = "@+id/imageLayout"> <ImageView android:id="@+id/loading_icon" android:layout_width="wrap_content" android:padding="10dp" android:layout_height="wrap_content" android:src = "@drawable/loading_ic"/> </RelativeLayout> <WebView android:id="@+id/webview" android:scrollbars="none" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layerType="software" /> </FrameLayout> 

MainActivity.java

  mWebView = (WebView) root.findViewById(R.id.webview); mWebView.setWebViewClient(mWebViewClient); mWebView.setWebChromeClient(mWebChromeClient); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false); 

White Text in AutoComplete

EDIT: solution

After working on this for several hours, I finally figured out what the problem was. I am posting a solution here so that it can be useful to others who might run into a similar problem. The problem, as I understand it, is how the WebView replaces the input fields on the web page. It overlays each input field on a WebTextView (part of WebKit). This WebTextView is a child of Android.Widget.Autocomplete. Basically, setting a style for autocomplete and DropDownItem seems to be the solution:

styles.xml

 <style name="ActivityTheme" parent="android:style/Theme.Light"> <item name="android:windowNoTitle">true</item> <item name="android:autoCompleteTextViewStyle">@style/Widget.AutoCompleteTextViewLight</item> <item name="android:dropDownItemStyle">@style/Widget.DropDownItemLight</item> </style> <style name="Widget.AutoCompleteTextViewLight" parent="@android:style/Widget.AutoCompleteTextView"> <item name="android:textColor">@android:color/primary_text_light</item> </style> <style name="Widget.DropDownItemLight" parent="@android:style/Widget.DropDownItem"> <item name="android:textColor">@android:color/primary_text_light</item> </style> 

Now apply the ActivityTheme to the activity in the manifest as follows:

 android:theme="@style/ActivityTheme" 

This link helped me solve the problem.

+4
source share

All Articles