I am developing an Android app in full screen mode. I want the screen automatically adjusted when a soft input is shown. I am using ScrollView to make my screen can extend larger than the maximum height. You can see the layout XML below:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="${packageName}.${activityClass}" >
<VideoView
android:id="#+id/taskdetail_bgvideo"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
<ScrollView
android:id="#+id/taskdetail_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- Other Widgets -->
</LinearLayout>
</ScrollView>
</RelativeLayout>
The VideoView in the background is placed as intended to create a background video in the overall layout.
I tried the workaround in Android How to adjust layout in Full Screen Mode when softkeyboard is visible but somehow in my case, it doesn't work as expected. When I choose the bottommost TextView, all screen somehow pushed upwards to the top, leaving a very big black area between soft keyboard and the activity screen. Check the screenshot below (Sorry, still low reputation, so cannot post the image directly :( )
Giant blackhole
So do you have any possible idea to tackle this weird behavior? In addition, I also have tried setting the softInputMode to ADJUST_RESIZE or ADJUST_PAN, and both settings did that. When I set it to ADJUST_NOTHING, nothing really adjusted at all.
When I don't use the workaround I mentioned above, I cannot scroll the view to the bottommost widget, but somehow the window view is panned to the focused TextView. I believe that this is actually the major culprit, but I don't know how to fix it.
Thanks in advance :)
If you have the property <item name="windowFullscreen">true</item> in your theme then the android:windowSoftInputMode="adjustResize" doesn't work.
Try change
<ScrollView
android:id="#+id/taskdetail_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
to
<ScrollView
android:id="#+id/taskdetail_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent" >
you have to write
android:windowSoftInputMode="stateHidden|adjustPan"
in your manifest file
Try to add below properties to your <activity tag declaration in AndroidManifest.xml
android:windowSoftInputMode="stateHidden|adjustPan"
Related
I know there are lots of questions about this but none of the answers are working for me. Here's a screen in question before opening the keyboard.
Here's the screen after opening the keyboard by tapping on an EditText, and then scrolling as far down as possible.
Note that besides the final edit control being mostly concealed, all the text and the button after it are inaccessible.
Here's the fragment layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:validator="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity$PlaceholderFragment"
android:background="#color/background">
<TextView android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/primary"
android:text="#string/help_header"
android:textSize="20sp"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
/>
<TextView android:id="#+id/drop"
android:layout_below="#id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/help_sub_header"
android:textSize="16sp"
android:textColor="#color/material_drawer_secondary_text"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_marginBottom="#dimen/activity_vertical_margin"
/>
<View android:id="#+id/divider1"
android:layout_below="#id/drop"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/light_gray_background"
android:layout_marginBottom="#dimen/activity_vertical_margin"/>
<LinearLayout android:id="#+id/linear1"
android:layout_below="#id/divider1"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin">
<!-- Several EditTexts and such -->
</LinearLayout>
</RelativeLayout>
</ScrollView>
It was originally in a LinearLayout and I changed it to a RelativeLayout based on a suggestion, but that didn't change anything. I have also played with the layout height (wrap_content / match_parent) of the top two levels of view groups to no effect. Here is the activity declaration in the manifest:
<activity
android:name=".MainActivity"
android:label="#string/application_name"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
I've also tried adjustPan and it doesn't seem to change. I'm not too concerned about what exactly the UI elements do when the keyboard opens, I just want the whole layout to be accessible by scrolling.
Basically everyone points to the soft input mode, but that doesn't seem to be doing anything. Is there something about fragments that I'm missing? Or maybe this is harder than I'm expecting and I need to make a custom layout class and measure the layout and nasty stuff like that? I can add the activity layout though there's not much to it, or code such as the fragment creation/transaction stuff.
THat's what the keyboard does. It covers the bottom of the screen. If you want it to not cover your app at all, you can use adjustResize. That will scale your app to only draw in the top half. But if your content is too big it still won't fit and it will look as if your app is covered (even though it isn't. Scrolling it via a scroll view should work then (although I've never actually tried it). But the only thing you can do to control the behavior when the keyboard is up is the softInputMode.
If you have lots of adjustable space or whitespace, there are techniques that will shrink you somewhat and may allow your full app to appear in the reduced space. This isn't the case here, you have too much stuff on screen (except for maybe on a tablet in portrait mode). So they aren't going to apply here.
It turns out the problem was with a library, material-drawer (nice library). For anyone else encountering this:
https://github.com/mikepenz/MaterialDrawer/blob/master/README.md#i-have-problems-with-the-softkeyboard-how-can-i-fix-this
Call Drawer.keyboardSupportEnabled(this,true) and the layout will arrange and scroll appropriately.
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>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<LinearLayout
android:layout_gravity="bottom"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
in manifest:
android:windowSoftInputMode="adjustPan"
Initial behavior:
Current behavior:
Desired behavior:
How to achive desired behavior of layout? adjustResize unsuitable because this option resizes layout.
Thank you for answers!
The only way to obtain that result is resize layout.
Use android:windowSoftInputMode="adjustResize"
You probably want to take a look at this answer. A suggestion from it:
Set Window SoftInput Mode property to adjustPan and adjustResize
<activity android:windowSoftInputMode="adjustPan|adjustResize"> </activity>
try this one in your manifest:
android:windowSoftInputMode="adjustResize|stateUnchanged"
the check if the layout that contain EditText and Button is RelativeLayout.
Try to change FrameLayout to RelativeLayout with alignParentBottom="true" property in your LinearLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<LinearLayout
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
You won't be able to implement that with adjustPan, because from the official guide
The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.
Your Button is below your current focus EditText
by removing below line from activity and android:windowSoftInputMode from manifest, I got whole layout scrolling which was previously hiding by
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
please check this output video link:
https://mega.nz/#!TpRCWZjY!TqDzv0Yn3Q24PR1JAdH8kRVeDf2iSa1LQbNBgF0SVHk
I don't believe there is a simple way to do this. At least not as simple as setting a flag.
I had a similar situation of wanting the keyboard to rise to the level of Views well below the selected EditText. I ended up using this answer:
How to check visibility of software keyboard in Android?
and manually adjusting my View sizes when the keyboard becomes visible.
Just use this property in activity
android:windowSoftInputMode="adjustPan"
I like the Android market apps design, very bright and catchy layout. How it has been done? i tried to put such green semi-circle bar on top with transparency on circle, but my listview is not going behind, where in market apps listview scrolls behind the green bar.
Many thanks in advance.
Rgds
Balaji
I don't know exactly you want this or not but it may help you.
xml layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.v7.widget.Toolbar
android:id="#+id/my_awesome_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/transparent">
</android.support.v7.widget.Toolbar>
in Manifest file
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.NoActionBar" >
Color.xml
<color name="transparent">#64000000</color>
As a way I can suggest something like this:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<View
android:id="#+id/top_place_holder"
android:layout_width="fill_parent"
android:layout_height="100dip"
/>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/top_place_holder"
/>
<View
android:id="#+id/your_top_panel"
android:layout_width="fill_parent"
android:layout_height="130dip"
androis:background="#drawable/your_transparent_semi_circle_here"
/>
So it goes like this:
#id/top_place_holder is used to take some space and push the ListView down a bit, so it won't take the whole screen.
#id/your_top_panel is a top panel (the one that will hold your transparent semi circle stuff). It must be a little bigger (in height) than place_holder since it'll cover it and a bit of it will be hovering over the list view, so it would look, like the list view is below.
To not make the actual list elements hide below the top panel - set a header view for your ListView (ListView.addHeaderView()) that will take some space and won't let the first row of data to hide below the top panel.
That above is, of course, a hack way. The best way is to layout components yourself programmatically, so you won't be needing any place_holders and your sizes wouldn't be so hardcoded.
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.