How make my screen goes up together with keyboard? - android

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?

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.

Accessibility focus for UI element on Parent Fragment

I'm trying to add accessibility support ( Screen reader ) for a screen similar to below
Button 1 & Button 2 are part of a single fragment and TextView is part of a different child fragment.
When navigating with the screen reader on the focus moves from
Button 1 > TextView
When swiping left from TextView the focus doesn't reach Button 2. Instead, the focus is received again by Button 1.
How can I make sure the accessibility focus is correctly received by Button 2.
Layout of parent fragment
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:text="Button 1" />
<android.support.design.widget.CoordinatorLayout
android:id="#+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button_container"
android:overScrollMode="never">
</android.support.design.widget.CoordinatorLayout>
<FrameLayout
android:id="#+id/button_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:clickable="true"
android:focusable="true"
android:gravity="center">
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:importantForAccessibility="yes"
android:text="Button 2" />
</FrameLayout>
</RelativeLayout>
Layout for child fragment
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:importantForAccessibility="yes"/>
</android.support.constraint.ConstraintLayout>
Note: If this layout is tested on most devices the focus will come to Button 2 without extra work. But that's not the case in some samsung devices (s8,s9)
I tried the following approach
Identify when TextView is in focus in accessibility mode
Identify the touch on the screen and identify swipe right
Programmatically get focus on Button 2 by firing AccessibilityEvent.TYPE_VIEW_FOCUSED
I was not able to accurately identify the swipe right gesture in accessibility mode.

Push only the bottom part up when Soft keyboard appears

The only thing I am trying do that there will be an editText at the top and after that there will be an ImageView.
Now at the bottom line there will be some buttons (ex. emojis) and this bottom part will only be pushed up by the soft keyboard whenever it will appear.
I am making it more clear by attaching this layout of Facebook.
required output
I have gone through all these SO questions and also tried their answers but no luck. May be I am doing something wrong.
Android: Resize only parts of view with soft keyboard on screen
Android: How do I prevent the soft keyboard from pushing my view up?
android : How to prevent resizing the window when displaying the virtual keyboard
My XML code
<ScrollView
android:id="#+id/scrollOnPost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:isScrollContainer="false"
android:fillViewport="true"
android:layout_below="#+id/header_layout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="4"
android:layout_gravity="bottom"
android:gravity="bottom">
<EditText
android:id="#+id/ed_post"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ImageView
android:id="#+id/img_posted_list_row"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2.7"
android:adjustViewBounds="true"
android:src="#mipmap/ic_launcher"
android:scaleType="fitCenter"
android:background="#color/red"/>
</LinearLayout>
</ScrollView>
<ImageButton
android:id="#+id/imgBtn_Emoji"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:src="#drawable/smile_face"
android:background="#drawable/button_pressed_white"
/>
All I getting that my soft keyboard always pushing the whole layout up not just the emoji at the bottom. Thanks.
Dude it worked
manifest :
<activity android:name=".TestActivity"
android:windowSoftInputMode="adjustResize"/>
xml :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="#+id/scrollOnPost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:isScrollContainer="false"
android:fillViewport="true"
android:layout_below="#+id/header_layout"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="4"
android:layout_gravity="bottom"
android:gravity="bottom">
<EditText
android:id="#+id/ed_post"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ImageView
android:id="#+id/img_posted_list_row"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2.7"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:background="#color/colorPrimary"/>
<ImageButton
android:id="#+id/imgBtn_Emoji"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:src="#mipmap/call"
/>
</LinearLayout>
I guess you want only the editText to push up when keyboard is visible(Correct me if i am wrong) for that i have got an idea i don't know if it will work or not you can try it out if you find it logical
Idea is to first check if keyboard is visible or not and secondly if visible get its height and programatically give your layout a marginBottom which will be equal to the height of keyboard(using layoutParams).
check this links for implementing above idea :
How to capture the "virtual keyboard show/hide" event in Android?
Is there any way in android to get the height of virtual keyboard of device
How to set RelativeLayout layout params in code not in xml

android questions about poping the soft keyboard

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>

Soft-keyboard appears every time layout becomes visible

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);

Categories

Resources