i have an activity with an editText field almost at the bottom.
when i focus on that editText field the keyboard shows up and pushes my edittext field up.
when it stops there is no space between editText and my softkeyboard.
is it possible to add some margin?
this is my 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="wrap_content"
android:background="#color/bg_yellow"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true"
android:paddingTop="25dp"
>
<RelativeLayout
android:layout_width="340dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
>
<EditText
android:layout_width="340dp"
android:layout_height="45dp"
android:background="#drawable/edit_text_field"
android:inputType="text"
/>
</RelativeLayout>
</RelativeLayout>
position of editText field before keyboard shows up:
http://postimg.org/image/826fwy18z/
and an image when keyboard is show up, with no space between cursor and keyboard:
http://postimg.org/image/97qlfb4zx/
You can use android:windowSoftInputMode property of Activity in manifest file.
Use android:windowSoftInputMode="adjustResize" in your case. You can check other properties as well.
Hope this helps.
Thanks.
Add margin to the bottom of the edit text field
android:layout_marginBottom="10dp"
Related
I placed an edit text within a scroll view with height = match_parent and expected its height to be equal to the scroll view but it's not. Its height behaves like wrap_content which means if there are no text in the EditText, I will have to point the cursor at the first "line" for the soft keyboard to popup, what I want is I can touch anywhere in the screen (the scroll view) and the soft keyboard pops up.
Below is the layout, thanks for your helps.
<LinearLayout 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"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:gravity="top"
android:padding="10dp"
android:textSize="16sp"
android:textColor="#android:color/black">
</EditText>
</ScrollView>
<Button
android:id="#+id/btnPaste"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/paste"
android:gravity="center"
android:onClick="pasteData"
android:layout_marginLeft="5dp"
android:layout_marginRight="6dp"
android:layout_marginBottom="5dp"
android:background="#drawable/rounded_corner_button"
android:textColor="#android:color/white"/>
</LinearLayout>
Layout capture :
Add this line in your ScrollView.
android:fillViewport="true"
You can control the edit text by changing minLines attribute
for example :
<EditText
android:id="#+id/ed_comment"
style="#style/EditText.NoBackground"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:hint="#string/write_comment_hint"
android:minLines="40"
android:textSize="16sp"/>
and instead of wrapping the EditText by scrollView add this attribute to editText
android:scrollbars="vertical"
result:
Implement this to your EditText in xml file:
android:scrollbars="vertical"
Implement this in onCreate():
editText.setMovementMethod(new ScrollingMovementMethod());
Then, you won't need scrollview if you only use it for textview, it simply makes scrollable only your textview.
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
I need an activity that look like a simple text editor: full-screen EditText with submit button below it.
Important:
1. EditText has to scroll both vertically and horizontally
2. Input text goes to the next line ONLY when the user clicks nextline button
3. EditText fills the whole space between the top of the screen and the button
My code:
<LinearLayout 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"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<EditText
android:id="#+id/some_edittext"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top|left"
/>
</HorizontalScrollView>
</ScrollView>
<Button
android:id="#+id/submit_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit"/>
</LinearLayout>
Why bad:
EditText AUTOMATICALLY breaks text to the next line as it reaches the end of the row
It worked fine before I set fillViewport to true. But otherwise EditText doesn't fill entire screen
Thanks in advance
EditText actually has scrolling already built in, so you don't have to use a ScrollView. The only thing is that it doesn't support flings.
<LinearLayout 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"
android:orientation="vertical">
<EditText
android:id="#+id/some_edittext"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top|left"
/>
<Button
android:id="#+id/submit_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit"/>
</LinearLayout>
To stop the automatic wrapping, you can activate horizontal scrolling:
EditText editText = (EditText) findViewById(R.id.some_edittext);
editText.setHorizontallyScrolling(true);
editText.setMovementMethod(new ScrollingMovementMethod());
I think you could set your EditText attribute android:maxLines="1" initially.
And when "new line" button is clicked, you can increase that value programmatically using setMaxLines(int) method.
EditText.setMaxLines(int)
here's the doc -> link
Hope this helped.
I have this typical issue when soft keyboard appears for user to enter input and covers the EditText where text should appear.
I tried many different "fixes" and solution without success. I guess there is certain combination in my layout that causes this issue.
Right now in AndroidManifest.xml I have this line
<activity
android:screenOrientation="landscape"
android:windowSoftInputMode="adjustPan">
The layout with the EditText is as follows witht he EditText at bottom
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars = "vertical"
android:windowSoftInputMode="adjustPan|adjustResize">
<LinearLayout
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/cargoRoot"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:numColumns="auto_fit"
android:stretchMode="columnWidth" >
<LinearLayout
android:layout_height="wrap_content" android:layout_width="600dp"
android:orientation="vertical" >
<TextView style="#style/smalltext" />
<TextView
android:id="#+id/arrivalEta"
android:layout_height="wrap_content" android:layout_width="wrap_content" />
<TextView
android:text="#string/cargoComments"
style="#style/smalltext" />
<ScrollView android:id="#+id/scrollEditCargoComments"
android:layout_width="fill_parent" android:layout_height="142dp"
android:scrollbars="vertical">
<EditText
android:id="#+id/editCargoComments"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="#dimen/text_normal"
android:minLines="5"
android:imeOptions="actionDone"
android:imeActionLabel="#string/send"
android:inputType="textNoSuggestions" />
</ScrollView>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
Other things worth commenting is that I have this EditText with visibility gone until certain points in the app where the user is prompted to enter comments. Then I change visibility to visible and when user taps on the text the soft keyboard appears.
It appears hiding everything behind it. No Resize or Pan operation is done.
The view that holds the EditText is infalted code-behind and inserted inside another view inside a PopupWindow.
So is like MainActivity > PopupWindow > ViewFlipper > EditText
I wonder if either PopupWindow or ViewFlipper add some poison to soft keyboard management.
Thanks in advance
Try this:
android:windowSoftInputMode="adjustResize|adjustPan|stateHidden"
In my application I want to have a layout like this:
I did it with a Relative Layout holding an ImageView, TableLayout and a Button. The problem is that when I open the keyboard to modify a EditText the keyboard is on top of the EditText, so the user can't see what he is writing. I want the layout to be like this when the keyboard is shown:
The user should be able to scroll up the view to see the whole image while the keyboard is shown, even if he doesn't see the EditText then, because he wants to copy some data of the image into the EditTexts. I tried to do it like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/buttonEditStop"
android:padding="10dip" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/stopImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:clickable="true"
android:contentDescription="#string/entry_img"
android:onClick="ImageClick" />
<TableLayout
android:id="#+id/formLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/stopImg"
android:layout_marginRight="10dp" >
...
</TableLayout>
</RelativeLayout>
</ScrollView>
<ImageButton
android:id="#+id/buttonEditStop"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:contentDescription="#string/edit_stop"
android:onClick="EditButtonClicked"
android:src="#drawable/ic_menu_edit" />
Using this code my whole layout is screwed. I see the form on top of the image, followed by a ImageButton with the image that should be seen in the imageView.
Anyone knows how I can get a layout like the one I want?
Thanks!
To avoid the EditText to be overlapped I had to use
android:windowSoftInputMode="adjustPan"
in my manifest.