Android Keyboard showing resize activity - android

I'm trying to resize my activity when EditText become first responder and keyboard is showing.
For now I have used android:windowSoftInputMode="adjustResize"in my AndroidManifest.xml. It works great but when keyboard is showing I can see the previous activity in the background. Is that normal?
Both activities have white background so I'm wondering what am I doing wrong?
My second activity xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white">
<TextView
android:id="#+id/topView"
android:background="#color/HWMMainColor"
android:textColor="#color/white"
android:layout_width="match_parent"
android:layout_height="60dp"
android:padding="6dip"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLinearLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.0" />
</LinearLayout>
Thanks

Related

dialog partially hidden

Inside some Activity I have Button, which opens Dialog (marked as Fragment on pic).
In this Dialog I have some other Button and EditText.
By default, focus set to EditText.
The problem is, when the Dialog is opened, it's not shown completely. The Button is hidden behind the screen (Screen and Hidden sections on pic), so I have to scroll up to see the Button.
I've tried to disable EditText focus, tried to set focus to Button, but Dialog is still not fully shown.
Is there any way I can force the Dialog to open completely?
It appears, that the Dialog covers exactly half of the Screen. If I don't have a lot of elements inside, it shown completely, if I do - I have to scroll.
UPD:
My Dialog uses custom XML with the following structure:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="wrap_content"
android:minHeight="300dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="16dp">
<TextView
android:id="#+id/title"/>
</LinearLayout>
<RelativeLayout
android:id="#+id/someid"
android:layout_width="match_parent"
android:layout_height="300dp"
android:visibility="gone"
tools:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:visibility="visible">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="270dp"
android:orientation="vertical"
android:visibility="visible"
tools:visibility="visible">
<LinearLayout
android:id="#+id/editTextLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone"
tools:visibility="visible">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="13dp"
android:gravity="bottom"
android:orientation="horizontal">
<EditText
android:id="#+id/EditText"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<Button
android:id="#+id/Button" />
</LinearLayout>
<View
android:id="#+id/overlayButtons"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white_70"
android:visibility="gone"
tools:visibility="gone" />
</RelativeLayout>
</LinearLayout>
P.S. the structure is complex, because I have a lot of other elements like Buttons, Text etc. inside. I've deleted them and left only important one like Linear/Relative layouts.
Ok, so I've figured it out.
It's impossible to define dialog`s height via layout, so I had to do it in the code.
Here is code snippet:
DisplayMetrics displayMetrics = getActivity().getResources().getDisplayMetrics();
int height = displayMetrics.heightPixels;
int maxHeight = (int) (height*0.75);
final BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from((View) view.getParent());
bottomSheetBehavior.setPeekHeight(maxHeight);
So now, dialog can occupy up to 75% of screen height if needed.

Move elements in Layout when keyboard is shown

I inflate a pop-up layout, where I implement some kind of chat. At the bottom (align parent bottom) I have EditText, where I can type message. And I have a ScrollView with LinearLayout, that uses left space of a layout. Messages appear in ScrollView. The problem is how to move elements when keyboard is shown. For example, I tap on EditText and soft keyboard appears above EditText, so I don't see what I'm typing. How to move it?
I tried to use windowSoftInputMode in manifest with adjustResize or adjustPan but it didn't help.
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="320dp"
android:layout_height="500dp"
tools:context="shkatovl.osanka.MainActivity"
android:background="#drawable/border_popup"
android:focusable="true">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="match_parent"
android:layout_height="350dp"
android:layout_marginTop="100dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="58dp">
<LinearLayout
android:id="#+id/llDialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="58dp"
android:background="#drawable/rect8"
android:layout_alignParentBottom="true">
<EditText
android:id="#+id/etDialog"
android:layout_width="244dp"
android:layout_height="38dp"
android:textSize="16sp"
android:textColor="#color/font"
android:hint="Сообщение"
android:paddingStart="15dp"
android:textColorHint="#color/font40"
android:background="#drawable/rect9"
android:theme="#style/EditText"
android:text=""/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>

scrollview not scrolling to bottom of the screen

I have a difficulty with implementing scroll view while using Theme.Black.NoTitleBar.Fullscreen.
When the user opens the application and click on editText the keyboard opens but the user cannot scroll beneath the edittext.
After many attempts I figured it something to do with the theme I am using (fullscreen)
This is my code .xml:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fadeScrollbars="false"
android:fillViewport="true"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<View
android:id="#+id/vieww"
android:layout_width="match_parent"
android:layout_height="1000dp"
android:background="#android:color/holo_green_dark" />
<EditText
android:id="#+id/test_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/vieww" />
<View
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#id/test_edit"
android:background="#android:color/holo_blue_bright" />
</RelativeLayout>
When the keyboard is opened the user cannot see the lowest view beneath the edittext.
What I tried so far:
I played a lot with windowSoftInputMode of the activity I tried combination of adjustResize/adjustPan but nothing seems to work.
I tried to change the container to LinearLayout but it still not working for me
I found a solution here here
The problem with this solution I need to change the minSdk to 19, when the application starts I can see black stripe where has been the title bar.
the other issue is when the user open the keyboard by pressing on edittext the title bar returns
I think you should put the ScrollView in a Relative Layout, so you can fit the size, if the keyboard appears.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fadeScrollbars="false"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<View
android:id="#+id/vieww"
android:layout_width="match_parent"
android:layout_height="1000dp"
android:background="#android:color/holo_green_dark" />
<EditText
android:id="#+id/test_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/vieww" />
<View
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#id/test_edit"
android:background="#android:color/holo_blue_bright" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>

how to change layout when soft Keyboard is shown

I have the following layout for an activity...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:id="#+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical"
android:fillViewport="true"
android:background="#3ba4a4a4"
android:fadeScrollbars="true">
<TextView
android:id="#+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="false"
android:text="#string/test_text"
android:textSize="40sp"/>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="2dp">
<EditText
android:id="#+id/edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="#string/edit_text_hint"
android:layout_marginTop="8dp"
android:theme="#style/InputMethodTheme"/>
<ImageButton
android:id="#+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_send"/>
</LinearLayout>
When the soft keyboard is opening I want the end of the TextView to go up with the EditText...
Any Idea on How to do That?
The EditText is going up normally as it should but its blocking the text view
i have tried the following in the manifest file in my activity
android:windowSoftInputMode="adjustPan"
But the action bar disappears which i don't want...
UPDATE
I tried the following in the TextView
android:layout_gravity="bottom"
and it seems to react as i want it to but some of the
lines before it are getting removed and extra spaces are
being added after the last word...
Basically you need to listen to the keyboard opening event.
More How to capture the "virtual keyboard show/hide" event in Android?
Be careful when dealing with devices with soft navigation buttons e.g., Nexus 5, you may need to take the navigation bar height into consideration.

Webview not resizing when keyboard appears

Need to resize my webview similar to Cordova/Phonegap when keyboard appears.
Right now as per below code, My input text fields are getting overlayed by device keyboard. I want to squeeze height of webview and make it adjust height above device keyboard.
Activity code :
<?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:background="#drawable/bg_home">
<include android:id="#+id/head" layout="#layout/header" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="11dp"
android:layout_marginLeft="11dp"
android:layout_marginRight="11dp"
android:layout_marginTop="2dp"
android:layout_below="#id/head"
android:background="#drawable/overlay_bg2"
android:orientation="vertical"
android:padding="9dp" >
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:isScrollContainer="true"/>
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleLargeInverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="invisible" />
</FrameLayout>
</RelativeLayout>
Manifest Entries :
Theme android:theme="#android:style/Theme.DeviceDefault.NoActionBar.Fullscreen"
Activity keyboard control android:windowSoftInputMode="adjustResize"
As far as I know, If your activity (or application as a whole) is set to full screen; android:windowSoftInputMode="adjustResize" won't work.

Categories

Resources