Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show a WebView with Theme.Dialog style in Android

I declared a WebView activity in the manifest like this:

<activity android:name=".MyWebView"
    android:label="@string/app_name"
    android:configChanges="orientation|keyboardHidden"
    android:theme="@android:style/Theme.Dialog">
</activity>

The WebView looks like this:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     >
    <WebView android:id="@+id/webview"
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"
    />
</LinearLayout>

When I start this activity within my main activity, only the title of the dialog, containing the apps name, is visible but not the WebView. If I add a TextView to the LinearLayout, it is shown as well, but still the WebView is missing. If I don't apply android:theme="@android:style/Theme.Dialog" in the manifest, the WebView is displayed.

Why is that and how can I show a WebView in a dialog?

like image 897
Manuel Avatar asked Aug 29 '10 18:08

Manuel


People also ask

How to add alert dialogs in Android WebView?

What is use in Android? By default, WebView does not implement JavaScript alert dialogs, ie. alert () will do nothing. In order to make you need to firstly enable JavaScript (obviously..), and then set a WebChromeClient to handle requests for alert dialogs from the page:

How do I apply a style as a theme in Android?

Apply a style as a theme. You can create a theme the same way you create styles. The difference is how you apply it: instead of applying a style with the style attribute on a view, you apply a theme with the android:theme attribute on either the <application> tag or an <activity> tag in the AndroidManifest.xml file.

What is a theme in Android?

Android Themes. Hope you understood the concept of Style, so now let's try to understand what is a Theme. A theme is nothing but an Android style applied to an entire Activity or application, rather than an individual View.

How do I display a WebView in Android Studio?

Start by opening the layout resource file where you want to display your WebView, and then add the following: You’ll also find a WebView component in Android Studio’s palette. Then, in the XML file’s corresponding Activity, you’ll need to obtain a reference to your WebView and specify the URL you want it to display:


1 Answers

I found that it works if you change the webview to wrap_content rather than fill_parent. No idea why. It's probably a bug.

like image 191
brybam Avatar answered Sep 26 '22 13:09

brybam