Soft-keyboard appears every time layout becomes visible - android

I have two layouts within a fragment that I switch back and forth between by making one invisible and the other visible and visa versa. When the layout that contains an EditText becomes visible the soft keyboard automatically pops up. I have used the following in the manifest but it didn't help.
android:windowSoftInputMode="stateUnchanged"
I never explicitly request focus on the EditText and have even tried requesting focus on something else to no avail.
<?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:id="#+id/container">
<LinearLayout android:id="#+id/dial_pad_ll"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:layout_centerInParent="true"
android:background="#1E1E1E" android:layout_marginLeft="20dp" android:layout_marginRight="20dp">
<EditText android:layout_height="wrap_content" android:id="#+id/search_et"
android:layout_width="match_parent" android:layout_alignParentTop="true"
android:layout_marginTop="20dp" android:layout_marginBottom="10dp" >
</EditText>
<!-- Other widgets here -->
</LinearLayout>
<!-- Other Layout Here -->
</RelativeLayout>
Anyone know how to prevent this? Thanks.
Edit: I should also have mentioned that this doesn't happen the first time. I open layout 1 with the edit text, make it invisible, make it visible again, then the keyboard pops up.

try adding this to your activity.
this.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

Related

Android app freezes when app soft keyboard is displayed or hide

I have an activity which has a fragment. Inside that fragment, there are 5 fragmnets inside ViewPager. Each fragment has either more than 30 input fields including EditTexts, custom Dropdowns and Date Pickers or nested ViewPagers with fragments having same amount of input fields.
The problem is; when user taps on any EditText to input data, soft keyboard gets visible and when it is completely visible, the app freezes for around 2 seconds. When user presses back button to hide soft keyboard, keyboard gets off from screen and screen area which is underneath soft keyboard becomes white and app freezes again for same amount of time. This happens every time. Here is activity configuration from manifest:
<activity
android:name=".activities.HomeActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|adjustResize" />
I have tried different combinations for android:windowSoftInputMode nothing worked. Although this does not happen in other activities with same manifest configuration and with less number of fields. With so many input fields, its very annoying for user that app freezes after inputting data in textfields. Can anyone suggest me workaround for this?
I have found the solution. In most of the layouts, the views were aligned vertical to each other inside RelativeLayout using android:layout_below property like:
<?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">
<LinearLayout
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--nested form view containers-->
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/layout1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--nested form view containers-->
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/layout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/layout2"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--nested form view containers-->
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
I replaced root RelativeLayouts with vertical oriented LinearLayouts and it did the magic trick like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--nested form view containers-->
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--nested form view containers-->
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/layout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--nested form view containers-->
</RelativeLayout>
</LinearLayout>
</LinearLayout>
I am still looking for some technical details on how it impacts keyboard visibility states. Will update here if I find something.
I will need to hands-on debug to find the issue, but what I think I will do is:
Check whether this is actually because of those many fragments and input controls. Can you try with only 1 fragment instead of 5 fragments and see if the speed improves? If yes, then try to display a fragment at once (ex: if you change from tab 1 to tab 2, explicitly remove fragment 1 from the pager view hierarchy and explicitly add fragment 2 to the pager view hierarchy). If after you simplify your controls, you still see the freeze, then that might not be because of too many controls.
Check whether there is offending control(s).Maybe you have a control or two that unexpectedly do a routine that heavily taxed your resources. If from point #1 you can find a fragment that significantly slowing down your app when it gets displayed, you might want to check further into that fragment and controls inside.

Soft Keyboard Hiding ActionBar while using adjustPan

I need to set visible all these three items
1. ActionBar
2. ListView
3. EditText (at Bottom)
When i click on EditText, it pushed the background image and squeezed it. i saw some tutorials and used android:windowSoftInputMode="adjustPan" that solved the squeezing issue but created a new one. When the SoftKeyboard appears, it also hides the ActionBar. I have visited many questions , but none of them was actually helpfull. IS there any way to set ActionBar always visible whatever happening on screen etc...
EDITED
The xml of fragment used to display the ListView and EditText is :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="#id/android:list"
style="#style/ContactListView"
android:layout_width="match_parent"
android:layout_height="389dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:isScrollContainer="false" />
<TextView
android:id="#id/android:empty"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_above="#+id/editText1"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:text="#string/no_contacts"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:background="#android:color/holo_blue_dark"
android:ems="10"
android:imeOptions="flagNoExtractUi"/>
</RelativeLayout>
Edited (2nd)
Snapshots are:
Try using android:windowSoftInputMode="adjustResize|stateHidden" in your activity tag.
I have the same problem as yours with EditText inside a Relative layout before, after searching several thread all over internet I have failed, but I solve it by experimenting on it through adding bottom_padding to the EditText which fixed it.
try this code to manifest file and activity to change layout.
android:windowSoftInputMode="stateAlwaysVisible|stateHidden"

Android: Fixed Number Pad

I have an EditText and when clicked a numberpad slides up via android:inputType="number". When this happens though it pushes the TextViews above off of the screen. I was wondering if there was a way for the numberpad to always be shown (then I can have fixed positions for everything)?
(I do not have a lot on the activity, so it is not like I am trying to save space.) I want the user to be able to see the TextViews that get pushed off the screen because they are updated based on the input. Here is what it looks like:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Name" >
// TextViews that get pushed off
<EditText
android:id="#+id/editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="71dp"
android:layout_toLeftOf="#+id/enter_input"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>
</RelativeLayout>
Is this possible? Or is there a better way so everything is shown on the screen and so nothing is hidden?
You can add android:windowSoftInputMode="stateAlwaysVisible" to your activity in AndroidManifest.xml so it forces the keyboard to always show.
<activity android:name="[activity_path]" android:windowSoftInputMode="stateAlwaysVisible"/>

How make my screen goes up together with keyboard?

How I get notified when the keyboard is going up?
I has a FrameLayout and it doesn't get resized when it's goes up, so I need to translate the screen myself.
This is my actual layout XML
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:layout_weight="1">
<br.view.image.ScrollableImage
android:id="#+id/image01" android:layout_width="match_parent"
android:layout_height="match_parent" />
<br.view.TopBarView android:id="#+id/topBar"
android:layout_width="match_parent" android:layout_height="wrap_content" />
<br.view.BottomBarView
android:id="#+id/bottomBar" android:layout_gravity="bottom"
android:layout_width="match_parent" android:layout_height="wrap_content" />
</FrameLayout>
From inside the BottomBar I open a PopupWindow wich a EditText and a Button.
When touch the EditText, the soft keyboard just overlay the bottom of the screen covering even the popup window.
See this SO question Android: which event fires when on screen keyboard appears?

How to keep some of the components fixed when the soft keyboard comes in?

My application is a chat application, and its UI is:
Header of the app
List View
Chat message, input box, and send button
But the problem is when I click the edit text, the soft keyboard comes and pushes everything up, but I need the header to stay on the screen. I've attached the simplified problem images and UI code here. (I can't post multiple links or images in this post because I'm new to Stack Overflow.)
<?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">
<TextView android:text="Header contents" android:layout_width="fill_parent"
android:textSize="20sp" android:gravity="center_horizontal"
android:layout_height="wrap_content" />
<ListView android:id="#android:id/list" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1" />
<EditText android:text="" android:layout_gravity="bottom"
android:id="#+id/EditText01" android:layout_width="fill_parent"
android:layout_height="wrap_content"></EditText>
</LinearLayout>
Android has this requirement in the default messaging app.
Does anyone have any ideas?
The question is quite old, but anyhow - one way to fix this is to put everything that comes below the header within a ScrollView.
Example:
<!-- Both elements below are children of a parent RelativeLayout -->
<RelativeLayout
android:id="#+id/custom_action_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:isScrollContainer="false" >
<!-- Header goes here. -->
<!-- This part remains fixed even with the keypad popping up. -->
</RelativeLayout>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/custom_action_bar"
android:isScrollContainer="true" >
<!-- Rest of the UI -->
<!-- This part scrolls to accommodate the keyboard -->
</ScrollView>
The solution described here is the solution. Your fullscreen theme is responsible for Kamil Los not being able to reproduce your issue.
You need to adjust the activity's windowSoftInputMode tag, as described here.
Try adding the tag "android:windowSoftInputMode="adjustResize"" to the offending activity in your application's manifest.
That is quite strange, because I have created a new project, pasted your layout and the header does not disappear in my case (neither in 2.2 emulator nor 1.6).

Categories

Resources