Kotlin can't click on empty EditText - android

I am creating a profile activity and each row contain on one side a textview for the information about the row for exemple : Name, on the other side i have an EditText to change the information when we click on validate. here is the xml for each row :
<FrameLayout
android:id="#+id/first_name_row"
android:layout_marginBottom="#dimen/profile_row_bottom_margin"
android:background="#color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?android:attr/selectableItemBackground">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="#dimen/small_item_list_height"
android:paddingEnd="#dimen/default_padding"
android:paddingLeft="#dimen/default_padding"
android:paddingRight="#dimen/default_padding"
android:paddingStart="#dimen/default_padding">
<TextView
android:includeFontPadding="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginEnd="#dimen/default_padding"
android:layout_marginRight="#dimen/default_padding"
android:text="#string/acct_first_name"
android:textSize="#dimen/profile_row_text_size" />
<EditText
android:id="#+id/acc_name_first"
android:includeFontPadding="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="#dimen/default_padding"
android:layout_marginRight="#dimen/default_padding"
android:background="#null"
android:text="#string/acct_first_name"
android:enabled="false"
android:focusable="false"
android:cursorVisible="false"
android:textSize="#dimen/profile_row_text_size" />
</RelativeLayout>
</FrameLayout>
The problem is that I added android:background="#null" because I don't want the bar under the field. but when I do that I delete all character from the field, it's become empty and if I change to focus on another field, I can't click on the empty field.
Here you have the image, the field Nom is selected but we see that the field prename is empty so I can't select it. also, the field email work because I didn't put backgound = null but I don't want the bar under it.
Is there a way to have a Textedit that doesn't have a bar under it but can still be clickable is it's empty?

EditText has android:layout_width="wrap_content" once you remove all the char with becomes zero, next time even if you enable it you cannot click it. Use attribute android:minEms="1".

From my point of view it will be better to just add some minimum width to your edit text:
<EditText
android:id="#+id/acc_name_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginEnd="#dimen/default_padding"
android:layout_marginRight="#dimen/default_padding"
android:background="#null"
android:cursorVisible="false"
android:enabled="false"
android:focusable="false"
android:includeFontPadding="false"
android:minWidth="50dp"
android:text="#string/acct_first_name"
android:textSize="#dimen/profile_row_text_size" />

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:

TextView with inputType is still getting touchlistener when its pressed although its disabled

Im trying to display password using textView , I used inputType"textPassword" and its displaying doted password text which is what I want . This textView is inside relative layout I'm trying to get clicklistener from the relative layout but when I'm pressing above the textView its not clicking , when I remove the inputType it works fine. Here is what i tried till now .
`
<RelativeLayout
android:id="#+id/relativeLayout_changePassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
android:clickable="true"
android:descendantFocusability="blocksDescendants"
android:foreground="?selectableItemBackground"
android:padding="20dp">
<TextView
android:id="#+id/settings_password_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="#string/settings_change_password"
android:textColor="#color/text_color" />
<TextView
android:id="#+id/textView_settings_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/settings_password_title"
android:clickable="false"
android:enabled="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="right"
android:inputType="textPassword"
android:text="123abc[enter image description here][1]"
android:textColor="#color/colorPrimary" />
</RelativeLayout>`
You can set Input type pro-grammatically instead of xml file
<TextView
android:id="#+id/textView_settings_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/settings_password_title"
android:clickable="false"
android:enabled="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="right"
android:text="123abc[enter image description here][1]"
android:textColor="#color/colorPrimary" />
Then set Input type in activity
TextViewPassword.setInputType( InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD );
tv.setTransformationMethod(PasswordTransformationMethod.getInstance());
Have you tried setting the input type from java code instead of xml? Does that make a difference?
You have used
android:clickable="false"
android:enabled="false"
android:focusable="false"
for your TextView so it won't receive any Click Events only when you click outside of this TextView your layout will receive input clicks
Also inputType"textPassword" has no impact on View's click events.

How to give an `EditText` a label to its left side?

How to give an EditText a label to its left side?
You can combine textview/imageview with edittext for that, for example like this one :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/shape_edittext_border_red"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView <!-- this one should be your text or image-->
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginLeft="10dp"
android:src="#drawable/your_logo" />
<EditText
android:id="#+id/edit_mobile"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#null"
android:hint="#string/dialog_mobile"
android:inputType="phone"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#color/main_color"
android:textColorHint="#color/main_color"
android:textSize="14sp" />
</LinearLayout>
you can do something like this.
File->new->image asset-> here choose 1st drop down and select Action bars and Tabs Icons->then choose radio button Asset type Text->now next columns is Text here in "Aa" field Enter "F" and choose back ground.
now save it with some img.png
now In your EditText
write add android:drawableLeft="#drawable/img.png" like bellow
<EditText
android:id="#+id/edittext_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Child's First Name"
android:textSize="20sp"
android:drawableLeft="#drawable/img.png" />

Selection button does not work in Android TV

I do not understand why this layoutcan not be selected anything in android tv.
it's not possible select any button or whiget, or insert text.
Please help me, and if you can and tell the reason.
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/bTextUrl"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:background="#faf6f6"
android:layout_marginTop="60dp" />
<Button
android:layout_width="#dimen/latimea_button_send_tv"
android:layout_height="#dimen/inaltimea_button_send_tv"
android:text="#string/button_send_android_tv"
android:id="#+id/bSendUrl"
android:background="#drawable/button_send_tv"
android:layout_below="#+id/bTextUrl"
android:layout_alignParentStart="true"
android:layout_marginTop="35dp" />
<android.support.design.widget.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/bShare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right|end"
android:src="#android:drawable/ic_menu_share"
app:elevation="6dp"
app:borderWidth="0dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />
Firstly, you have to keep focus of any one of items (i.e. Button, TextView, etc.) as below. And also, you have to apply it's nextFocusDown, nextFocusLeft, nextFocusRight & nextFocusUp properties. So it will fire it's releveant event when you click TV remote navigation buttons.
Add request focus to your edit text like this,
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/bTextUrl"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:background="#faf6f6"
android:layout_marginTop="60dp"
android:nextFocusDown="#+id/bSendUrl">
<requestFocus></requestFocus>
</EditText>
<Button
android:layout_width="#dimen/latimea_button_send_tv"
android:layout_height="#dimen/inaltimea_button_send_tv"
android:text="#string/button_send_android_tv"
android:id="#+id/bSendUrl"
android:background="#drawable/button_send_tv"
android:layout_below="#+id/bTextUrl"
android:layout_alignParentStart="true"
android:layout_marginTop="35dp" />
</Button>
And after that, you can add more properties like nextFocusDown, nextFocusLeft, nextFocusRight, nextFocusUp to focus next item.

How to set an non editable text on left side of edit text in android?

As we all know that we can set a drawable_left on the EditText using
edittext.setcCompoundDrawablesWithIntrinsicBounds(R.drawable.icon,0,0,0);
Is it possible to set a non editable text say "A" on the left side of the edit text?
You can do this like this (The values are for example):
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A"
android:layout_marginRight="10dp"/>
<EditText android:layout_width="100dp"
android:layout_height="25dp"
android:id="#+id/editTextView"
android:layout_marginLeft="40dp"/>
</RelativeLayout>

Categories

Resources