Android EditText Layout like Gmail Compose Screen - android

I am trying to implement the following:
Please check the image here:
The problem is whenever the user taps the compose mail edittext field, the send/save/discard buttons are hidden by the softkeyboard.
Any ideas on how to make those buttons always visible?
Thanks.
[EDIT]
Finally got it solved!Had to use Linearlayout instead of RelativeLayout and assigning proper layout_weight parameter did the trick. Thanks a lot Femi for pointing out that the buttons need to be outside of the ScrollView.
Here is the final working layout xml in case anyone finds it helpful:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"><ScrollView android:layout_alignParentTop="true"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/InnerRelativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<EditText
android:id="#+id/editTextCompose"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:gravity="top"
android:singleLine="false" android:lines="5"
android:inputType="text"
android:layout_below="#+id/editTextSubject"
>
</EditText>
</RelativeLayout>
</ScrollView><TableLayout android:id="#+id/recipeButtons"
android:background="#B0B0B0" android:padding="3dip"
android:stretchColumns="0,1" android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow android:gravity="center">
<Button android:id="#+id/editOtherAdditionButton"
android:text="Save" />
<Button android:id="#+id/removeOtherAdditionButton"
android:text="Delete" />
</TableRow>
</TableLayout></LinearLayout>

As documented in #mayra's answer to Android soft keyboard covers edittext field you should see http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft for the details to control.
Modifying the Activity's entry in the AndroidManifest to adjustResize should I think do it.

There is another question about this here, but it looks like the best approach is using the windowSoftInputMode

Related

actionNext(or any ImeOption) doesn't work on my Edittext, also I can't select any other text field when this particular one is selected

This is such a confusing behavior to me, and I can't find anyone else with exactly my problem.
I am trying to create a login activity, and so far the username-field is giving me a lot of trouble. The textfield stays focused no matter what.
It doesn't lose focus if I click outside, I can't click any other field and I can't close the keyboard. Only back-button works in getting out.
I tried making it a one-line field by using every combination of SingleLine, MaxLines and Lines.... I also tried to use ImeOptions/ImeActionId actionNext which also had no effect.
It stubbornly keeps its enter-button that continues to create new lines despite setting SingleLine to true.
Right now my xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".LoginActivity"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:paddingTop="#dimen/spacing_huge">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/mini_logo"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="#dimen/spacing_huge">
<ImageView
android:layout_width="fill_parent"
android:src="#drawable/orange_ring"
android:layout_height="fill_parent"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerInParent="true">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/loginUsername"
android:hint="Username"
android:imeOptions="actionNext"
android:singleLine="true"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/loginPassword"
android:hint="Password"
android:inputType="textPassword"
android:textAlignment="center"
android:maxLines="1"
android:singleLine="true"
android:imeActionId="6"/>
<Button
android:id="#+id/loginButton"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="login!"
android:onClick="userLogin"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
Edit: ehm sorry, I forgot to ask the question.
Can someone tell me what's going on or if I misunderstood something or how to fix this? :) I really have no idea what I can do right now. Thanks for your help.
Combining android:maxLines="1" with android:inputType="text" works for you.
Add this line android:singleLine="true" to your EditText.

Android Title bar gets pushed up when edit text content increases

I have a relative layout which contains only the edit text view. But when content of edittext increases, my title bar gets shifted upwards. Most of the solutions I went through addresses the issue of shifting title bar when keyboard pops out. But I didn't found anything in case its content increases. I also used android:isScrollContainer="false" as suggested in this post How to avoid soft keyboard pushing up my layout?, but still the same issue. Is there a way to prevent it? Here is my xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroll_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="false"
android:background="#drawable/background" >
<EditText
android:id="#+id/hidden_edit_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="flagNoExtractUi"
android:inputType="textMultiLine"
android:singleLine="false"
android:paddingLeft="10sp"
android:paddingTop="5sp"
android:paddingRight="5sp"
android:scrollbars="vertical"
android:background="#android:color/transparent"
android:textSize="26sp" >
</EditText>
</RelativeLayout>
I managed to solve this issue by putting edittext in scrollview and replacing adjustPan with adjustSize in the manifest. This is the final working layout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background">
<EditText
android:id="#+id/hidden_edit_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:imeOptions="flagNoExtractUi"
android:inputType="textMultiLine"
android:paddingLeft="10sp"
android:paddingRight="5sp"
android:paddingTop="5sp"
android:singleLine="false"
android:textSize="25sp" >
</EditText>
</ScrollView>
try to run your code after removing :
android:background="#android:color/transparent"
make your relative layout height and width to wrap_content.......... probably works. since when text increases your complete layout shifts. Try it and please rpy
Usually this can be solved by adding the android:windowSoftInputMode="adjustPan" property to your activity in the AndroidManifest file.

Android : Soft Keyboard covering edit text up (adjustresize or adjustpan doesnt work)

Android Developers...
I am new in developing android application. Thus, i really ask for a slow or details explanation about the problem:
As the title, the soft keyboard always covering up the edit text. Non of the adjustresize or adjustpan works.
I already search this problem, some people say to make the application not fullscreen. I already make my own simple theme which only consist:
false
still/ it doesnt work. Thus, how to disable full screen correctly?
Some people say to use scrollview. Is it the only answer for it? because i would rather to use relative or linear layout.
is there any simple answer to make the soft keyboard behaves well?
Thank you so much for your help :D
Ps:
android:minSdkVersion="7"
I am targetting for 2.1
There is no such implicit theme on my manifest that state the theme is fullscreen mode.
The awkward is: my login activity, the edittext is sliding up to make a room for the soft keyboard. but whenever this activity is called again, the sliding up for edittext does not working.
this is my activity xml:
<?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:background="#color/bgcolor"
android:orientation="vertical" >
<TextView
android:id="#+id/textTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:clickable="false"
android:layout_gravity="center_horizontal"
android:text="Transfer Tanpa Berita" />
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="30dp"
android:text="No Rekening Tujuan: " />
<EditText
android:id="#+id/transferNoRek"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:inputType="number"
android:maxLength="20">
</EditText>
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="30dp"
android:text="Jumlah: " />
<EditText
android:id="#+id/transferJumlah"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:inputType="number"
android:maxLength="20">
</EditText>
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="30dp"
android:text="No HP Tujuan: " />
<EditText
android:id="#+id/transferNoHP"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:inputType="number"
android:maxLength="15">
</EditText>
<Button
android:id="#+id/transferButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Kirim"
android:onClick="validatePin">
</Button>
</LinearLayout>
I finally find the answer to my own problem.
I set android:windowSoftInputMode int the Tab Activity not the actual activity. In my opinion, its because the Tab activity is the one who calls other activities.
Thanks.

EditText goes out of the screen sometimes when virtual keyboard shows up

I am developing an application for Android.
I have a simple layout. A CheckBox, a Spinner and a Button at the top, a two line EditText at the Bottom which is displayed when the CheckBox is checked and another EditText which covers the rest of the space in the middle.
The problem is that when I am writing on the big EditText, sometimes the layout goes out of the screen on top and as a result I can't see what I am writing.
As a solution, I can set my layout to resize when the keyboard shows (using android:windowSoftInputMode="adjustResize" on the manifest.xml) but that won't be good since I do not want the 2 EditTexts to share the space left on the screen.
My layout code follows:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:id="#+id/button"
android:text="Push"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"/>
<CheckBox android:id="#+id/check_box"
android:text="Check"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" />
<Spinner android:id="#+id/spinner"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText android:id="#+id/text_2"
android:hint="#string/hint_2"
android:inputType="textMultiLine"
android:maxLines="2"
android:gravity="top"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:visibility="gone" />
<EditText android:id="#+id/text_1"
android:hint="#string/hint_1"
android:inputType="textMultiLine"
android:gravity="top"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="#id/spinner"
android:layout_above="#id/text_2"
android:layout_alignWithParentIfMissing="true" />
</RelativeLayout>
P.S. This thing happens only on my Wildfire and very rare on the Emulator. A friend's Desire HD didn't have any problem at all. I don;t know if this makes any difference...
Thanks in advance for your help.
Antonis
I have the exact same problem. I've tested and this only happens with EditText in multiline mode and when SoftInputMode is set to adjustPan. This is most probably an Android bug.
The only solution I've found is to remove adjustPan.

SoftKeyboard hiding EditText

I have a layout that uses an EditText to let users search a database and populate a ListView. The EditText is about 2/3 of the way from the top of the screen (positioned over an ImageView, and followed by some intro text.)
The problem is that the soft keyboard hides the EditText, so the user can't see what he's typing. (I disabled the auto-suggest.)
I've tried LinearLayout, RelativeLayout, paddings, and different alignments/centerings, but I still can't get it to work right. The EditText is either hidden, gets pushed off the top of the screen, or get "squished" and distorted.
Suggestions???
One possible workaround is to move the EditText to the top of the screen. However, this deviates from the graphic design that I was given.
Another possible workaround is for me to make the soft keyboard open in full screen (not sure how, though). This will still hide the EditText, but then I can re-enable the auto-suggestion so the user can see what he's typing... sort of... because he can only see the suggestions for what he's typing.
Here's my latest attempt. See "introFrame".
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout android:id="#+id/titleContainer"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:text="#string/title_string"
android:textSize="15sp" android:textColor="#FFFFFF"
android:textStyle="bold" android:paddingLeft="5dp"
android:layout_height="fill_parent" android:layout_width="wrap_content" />
</LinearLayout>
<FrameLayout
android:id="#+id/introFrame"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<ImageView
android:src="#drawable/main_search_image"
android:scaleType="center"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="140dp" >
<LinearLayout android:id="#+id/introSearchContainer"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
<EditText android:id="#+id/intro_search_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" Enter keyword "
android:imeOptions="actionGo"
android:inputType="textFilter"
android:maxLines="1" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button android:id="#+id/intro_search_button"
android:background="#drawable/custom_button_go"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<TextView
android:text="#string/search_intro"
android:textSize="15sp"
android:textColor="#FFFFFF"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
</LinearLayout>
</FrameLayout>
<LinearLayout android:id="#+id/listContainer"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#+id/itemlist" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:cacheColorHint="#00000000" />
<TextView android:text="No data found" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center"
android:textSize="16sp" android:textColor="#FFFFFF" android:id="#+id/android:empty" />
</LinearLayout>
</LinearLayout>
What you're looking for is the Activity's windowSoftInputMode attribute. You set this in your AndroidManifest.xml file, and give it a value such as:
adjustResize: "The activity's main window is always resized to make room for the soft keyboard on screen."
adjustPan: "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."
adjustResize will probably work for you, as long as you wrap the layout in a ScrollView. It may have negative effects if you have a bitmap image in the background, as it will be resized as well, in which case you may want to use adjustPan instead.
<activity android:windowSoftInputMode="adjustResize" />
or
<activity android:windowSoftInputMode="adjustPan" />
More information is available at the above link.
What has worked for me is to drop my highest-level LinearLayout in a scrollView (the ScrollView can only have one child). This allowed the entire activity/form to scroll up and not clutter the EditText in focus.
First, I set in my activity:
<activity android:windowSoftInputMode="adjustPan" />
Then I did the ScrollView thing I'm talking about:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- STUFF -->
</LinearLayout>
</ScrollView>
just use following in manifest...
<activity
android:windowSoftInputMode="adjustPan">
try giving the edit text a layout_weight (i.e. layout_weight=1) , this may have some other effects on your other layout items that you may have to work through, but this may help it stay visible when soft keyboard pops up

Categories

Resources