NextFocusRight doesn't focus on the right, but down - android

I'm work on an app with multiple edittext.
When an edittext take the whole width, the nextfocusdown is working properly.
But when there is two edittext at the same height (each edittext takes half of the width), I want to give the focus from the left one to the right one.
But when i write nextFocusRight="id/EDIT_RIGHT" in my xml, the focus doesn't goes to the right edittext but goes to edittext under the left one.
<!-- EDIT LEFT-->
<EditText
android:id="#+id/EDIT_LEFT"
android:layout_width="165dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:hint="#string/edit_left_hint"
android:nextFocusRight="#id/EDIT_RIGHT"
tools:ignore="Autofill"/>
<!-- EDIT RIGHT-->
<EditText
android:id="#+id/EDIT_RIGHT"
android:layout_width="165dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:hint="#string/edit_right_hint"
android:nextFocusDown="#id/EDIT_DOWN"
tools:ignore="Autofill"/>

You have to use like this -
<!-- EDIT LEFT-->
<EditText
android:id="#+id/EDIT_LEFT"
android:layout_width="165dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:hint="#string/edit_left_hint"
android:imeOptions="actionNext"
android:nextFocusRight="#+id/EDIT_RIGHT"
tools:ignore="Autofill"/>
<!-- EDIT RIGHT-->
<EditText
android:id="#+id/EDIT_RIGHT"
android:layout_width="165dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:hint="#string/edit_rgiht_hint"
android:imeOptions="actionNext"
android:nextFocusDown="#id/EDIT_DOWN"
tools:ignore="Autofill"/>
You should use android:nextFocusRight="#+id/EDIT_RIGHT" instead of android:nextFocusRight="#id/EDIT_RIGHT" because you are using this edittext before creating it and use imeOptions.

Related

How to maintain text padding on EditText when there are multiple lines

For an application that I'm working on, I have an editText that I allow users to input data into. I have defined padding on the input that is not maintained when multiple lines of text are entered in. For example:
After adding a second line of text:
As more and more lines are added, I'm also seeing that the position of the edittext in the parent view gets lower and lower:
My XML for the editText is as follows:
<EditText
android:id="#+id/message_edit"
android:layout_width="0dp"
android:layout_weight="0.75"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/dp_8"
android:layout_marginLeft="5dp"
android:layout_marginBottom="5dp"
android:background="#drawable/someBackground"
android:paddingLeft="#dimen/dp_12"
android:paddingRight="#dimen/dp_3"
android:elevation="3dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="Type here"
android:lineSpacingExtra="#dimen/dp_4"
android:textColor="#color/black"
android:textSize="#dimen/sp_17" />
I assume that both issues are related given but i'm not sure what the underlying cause is.
Instead android:paddingLeft and android:paddingRight use only android:padding to add padding on all side. Check below:
<EditText
android:id="#+id/message_edit"
android:layout_width="0dp"
android:layout_weight="0.75"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/dp_8"
android:layout_marginLeft="5dp"
android:layout_marginBottom="5dp"
android:background="#drawable/someBackground"
android:padding="#dimen/dp_12"
android:elevation="3dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="Type here"
android:lineSpacingExtra="#dimen/dp_4"
android:textColor="#color/black"
android:textSize="#dimen/sp_17" />
Result:

Android: TextInputLayout always leaves some space from top

I have this layout:
<LinearLayout
android:id="#+id/dialogCentralContent"
android:gravity="center_horizontal"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_below="#+id/phoneNumberInfo"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="20dp"
android:layout_centerHorizontal="true"
android:orientation="horizontal"
android:background="#drawable/edittext_white_rounded">
<EditText
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_weight="1"
android:gravity="center"
android:maxLines="1"
android:inputType="none"
android:focusable="false"
android:text="#={dataContext.phonePrefix}"
style="#style/Widget.App.PurchaseAmountEditText" />
<android.support.design.widget.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
tools:errorEnabled="true"
app:errorText="#{dataContext.validator.phoneValidation}">
<android.support.design.widget.TextInputEditText
android:layout_height="60dp"
android:layout_width="match_parent"
android:gravity="center"
android:maxLines="1"
android:inputType="phone"
android:text="#={dataContext.phoneNumber}"
style="#style/Widget.App.PurchaseAmountEditText" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
It looks like this:
As you can see the second EditText is rendered lower than the first one. When I look at it in the visual editor of Android Studio I can see that the TextInputLayout has some free space at its top, however setting paddingTop="0dp" didn't change anything. So how to make those two EditTexts render the same way?
By default, android.support.design.widget.TextInputLayout will leave room at the top for the floating hint text. If you're not using the floating hint, you can remove that space by adding the following to the opening <TextInputLayout> element.
app:hintEnabled="false"
The regular hint text will still be visible on the TextInputEditText when it's empty.
N.B. – This answer does not apply to the current Material Components version, which is markedly different than the original.

Material Design Input Text

Is there a way to create an input field that looks like the ones on this image - Icon on the left, input on the right - using only the default TextInputLayout?
I've tried several combinations, and the icon always stays inside the TextInputEditText. I've tried changing the TextInputLayout orientation to horizontal but it didn't work as well. Is there anyway of doing this without placing an ImageView and an EditText inside of another ViewGroup?
Below is the code I used to create an input field, but with the icon remains inside the TextInputEditText.
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Test"
>
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="#drawable/ic_bank_card_back_grey_24dp"
android:drawablePadding="#dimen/default_padding"
/>
</android.support.design.widget.TextInputLayout>
Does this fit the bill ? :
<android.support.design.widget.TextInputLayout
android:id="#+id/TextInputLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<android.support.v7.widget.AppCompatEditText
android:id="#+id/EditText1"
android:hint="code"
android:text="0044"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="phone"
android:minWidth="350dp"
android:drawableLeft="#drawable/cross"
android:drawableStart="#drawable/cross"
android:textColor="#00ff00"
android:textColorHint="#ff0000"
android:textCursorDrawable="#null"
/>
</android.support.design.widget.TextInputLayout>
image from code:

EditText won't write into single line

I'm making a calculator and user input is contained in EditText. Input is typed through buttons on screen, so Android keyboard is disabled. However, I want it to write all input in one line and when line reaches border, it needs to be ellipsized and then horizontally scrollable so you can reach whole text.
I tried doing this by setting android:maxLines="1" and android:ellipsize="end", but that doesn't work. Text is still in multiple lines, but only one line is visible and you need to scroll vertically to see other lines. I also tried using android:singleLine="true", but that makes EditText completely unusable.
This is EditText XML:
<EditText
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#color/colorBlue"
android:textAlignment="textEnd"
android:textSize="40sp" />
I think this will work for you. Let me know if it works.
<EditText
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#color/colorBlue"
android:textAlignment="textEnd"
android:textSize="40sp"
android:inputType="text"
android:maxLines="1"
android:lines="1"
android:scrollHorizontally="true"
android:ellipsize="end"/>
This post might help you as well.
For single line in EditText, you just need to set two properties:
android:inputType="text"
android:maxLines="1"
Adding this line in the edittext make scrollable singleline text.
android:inputType="textShortMessage"
**This example helps you to create multiline EditText in Android.**
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
tools:context=".MainActivity"
>
<!--
android:scrollbars="vertical"
It will display a vertical scrollbar if the EditText text exceed
3 lines (android:maxLines).
-->
<EditText
android:id="#+id/et"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginBottom="10dp"
android:hint="Multiline EditText by XML layout"
android:fontFamily="sans-serif-condensed"
android:background="#d3d7b6"
android:minLines="2"
android:maxLines="3"
android:scrollbars="vertical"
android:inputType="textMultiLine"
/>
<EditText
android:id="#+id/et2"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:padding="10dp"
android:fontFamily="sans-serif-condensed"
android:hint="Multiline EditText programmatically"
android:background="#d4d7a5"
android:layout_below="#+id/et"
/>
</RelativeLayout>

EditText doesn't show when I have focus in another

I have a layout where i have one image view, two edittext and one button,
when i clicked on the first edittext, i can't scroll to the second to fill it too, because of the virtual keyboard, here 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="match_parent"
android:gravity="center_horizontal" >
<ImageView
android:id="#+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:src="#drawable/logo"
android:contentDescription="#string/invokeme" />
<EditText
android:id="#+id/login"
android:layout_height="wrap_content"
android:layout_width="235dip"
android:ems="10"
android:layout_marginTop="25dp"
android:layout_below="#id/logo"
android:hint="#string/login" />
<EditText
android:id="#+id/password"
android:inputType="textPassword"
android:layout_height="wrap_content"
android:layout_width="235dip"
android:ems="10"
android:layout_marginTop="5dp"
android:layout_below="#id/login"
android:hint="#string/password" />
<Button
android:id="#+id/submitLogin"
android:layout_width="235dip"
android:layout_height="wrap_content"
android:ems="12"
android:text="#string/login"
android:layout_below="#id/password"/>
</RelativeLayout>
There might be more than one way around. First one may be that you can keep everything ( the whole relative layout) inside a ScrollView. Second way can be that you may establish a touch listener on your view, excluding the two EditText's. When anything other than those two EditText is touched, you can hide the keyboard from the screen. See How to hide soft keyboard on android after clicking outside EditText? for more. Hope it helps.

Categories

Resources