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?
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.
The best way I have found is a little trick like this:
Notice the 1000dp for minWidth and minHeight
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="1000dp"
android:minHeight="1000dp" >
<WebView android:id="#+id/web_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
The other way is to wrap content on the WebView but it wont expand until you load a webpage..so it will start small, then expand. This hackish way will make the large dialog at start.
I would think what you are doing would work. Maybe try to override the dialog class instead of the activity class.
Use the WebView as the root layout - without any surrounding element.
Don't know why it didn't work with the surrounding layout.
Related
i want the whole layout move up to show while popping the soft keyboard, but the button on the bottom of the view cannot be seen.
the AndroidManifest.xml:
<activity
android:name="cn.duckr.android.plan.PlanConfirmPaymentActivity"
android:windowSoftInputMode="adjustPan"
style="#style/base_activity_style"
android:theme="#style/confirm_payment_anim_theme" />
To ensure that the system resizes your layout to the available space—which ensures that all of your layout content is accessible (even though it probably requires scrolling)—use "adjustResize".
link
android:windowSoftInputMode="adjustResize"
You can put whole layout except the particular button in a ScrollView to achieve this.
like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView5"
android:fillViewport="true">
//put your contents here..
</ScrollView>
<ImageButton
android:id="#+id/ibSample"
android:layout_width="50dp"
android:layout_height="50dp"
android:adjustViewBounds="true"/>
</RelativeLayout>
ScrollView does not work, I have a layout with some components like EditText, and when I'm typing something EditText keyboard rises, and along the component, however it appears above the other, the ScrollView does not respond to their function.
Already googled, and found some similar problems, but none solved my problem.
Below my layout.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars="none" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:padding="5dp" >
<TextView
android:id="#+id/txtDescricaoDocumento"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/edtDescricaoDocumento"
android:layout_alignBottom="#+id/edtDescricaoDocumento"
android:gravity="right"
android:text="Descrição:"
android:textAppearance="?android:attr/textAppearanceMedium" />
...
And my manifest.xml
<activity
android:name=".LancarDocumentoAcaoActivity"
android:windowSoftInputMode="adjustResize" >
</activity>
Couple things I've tried this without the relative layout inside of the scroll view...and scroll view worked perfectly.
1.Is relative layout necessary inside a linear layout? Try removing it if not.
2.Is the attribute WindowSoftInputMode necessary for the corresponding class if not you will have the soft keyboard covering view elements like it is mentioned.
Let me know if this works.
I have a simple WebView in my layout, with the following setup
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rootView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/baserepeat"
android:gravity="top|center_horizontal"
android:orientation="vertical"
android:paddingBottom="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp" >
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/productDetailContentWebview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#drawable/baserepeat" />
//other items...
Inside my manifest I have the containing activity set to
<activity
android:name=".Products.ProductDetailActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="sensor"
android:theme="#style/Theme.CPS" >
</activity>
My Webview is populated with a simple HTML file on the device, which works nicely. The problem is that when I rotate the device from portrait to landscale, the webview becomes a good deal taller, pushing whatever was below it further down in my layout. The amount of content doesn't change - it is all set in OnCreate().
I'm using the Webview to render the content with it's own special stylesheet, and it must stay within the ScrollView.
I can provide more information if required :)
I had the similar issue when working on 2.3/4.0...
I tried several things but the solution which helped me in getting rid of the core issue was:
removing screenSize from android:configChanges in AndroidManifest.xml
Hope it helps !!!
Try including your webview inside a FrameLayout.
<LinearLayout>
<FrameLayout>
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/productDetailContentWebview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#drawable/baserepeat" />
</FrameLayout>
My layout looks like this:
<RelativeLayout>
<RelativeLayout>
</RelativeLayout>
<ViewFlipper>
<ScrollView>
<LinearLayout>
<EditText />
</LinearLayout>
</ScrollView>
</ViewFlipper>
<RelativeLayout>
</RelativeLayout>
</RelativeLayout>
When focused on the EditText in the middle, the soft keyboard pops up as expected, However it always resizes the layout even though I have android:windowSoftInputMode="adjustPan" in the manifest.
The problem with resizing is that only the ScrollView shrinks, leaving the RelativeLayouts above and below it intact, which can almost completely obscure the EditText.
I've tried hiding the RelativeLayouts when the keyboard is shown (that's another sad story), but adjustPan sounds more suitable. However it has no effect on this activity.
How can I force adjustPan to work despite the presence of the ScrollView?
Update:
SO won't let me answer my own question, but the solution is setting android:isScrollContainer="false" on the ScrollView.
Good question mostly Developers do the same thing but this is not a correct way you have need to do. This will help you.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ViewFlipper>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<EditText />
</LinearLayout>
</ScrollView>
</ViewFlipper>
<LinearLayout>
You should take LinearLayout with orientation as Vertical or horizontal view where you have never adjustment problem created.this is very simple.
try this in your manifest's the activity tag:
android:windowSoftInputMode="stateVisible|adjustPan"
I have an Android application that is a TabHost with a WebView. I use it to load a specific html file that has a text field in its bottom part.
When I touch the html textfield, the soft keyboard pops up, and hides the textfield, so that I cannot see what I have typed.
Here is the layout:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TabWidget
android:focusableInTouchMode="false"
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="63dp" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout"
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"
android:layout_weight="1" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
I have tried to configure the AndroidManifest.xml file with android:windowSoftInputMode="adjustResize" with no success. I have also tried replacing the FrameLayout in my layout with ScollView, but that caused my webview to increase in size indefinitely when the application is running.. this may be due to some javascript I have running on the page.
I have noticed that the android's web browser has a nifty behavior - in a web page, after the soft keyboard pops up, the web page scrolls smoothly so that the focusable textfield is visible to the user. How can I have this kind of behavior in my application?
I was getting crazy nothing works android:windowSoftInputMode="adjustResize" may help but be sure to have your app not in full screen.
Removing full screen for my app solved the problem with the layout resize with softkeyboard.
<item name="android:windowFullscreen">false</item>
I found a solution for this issue. (about a week after I posted the question; I only got to answering in stackoverflow today...)
I had pieces in my code that changed the WebView's height (to have room for a TabBar). Turns out that when you invoke setLayoutParams on a WebView, it will no longer change its height even if you have android:windowSoftInputMode="adjustResize" set.
I circumvented the need to change the WebView's height by adding the TabBar to the main.xml layout file, with an initial size of 0. When I increase the TabBar's size, the WebView's size decreases automatically, and it preserves the android:windowSoftInputMode="adjustResize" behavior.