how to show both PasswordToggle icon and background drawable in TextInputLayout? - android

I want to set a background drawable for my TextInputLayout , this is my code :
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_repass"
android:layout_width="match_parent"
android:layout_height="37dp"
android:layout_marginTop="10dp"
app:hintEnabled="false"
android:layoutDirection="rtl"
app:passwordToggleEnabled="true">
<EditText
android:id="#+id/repass"
style="#style/edittexts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/hint_repass"
android:drawableRight="#drawable/ic_https_grey600_18dp"
android:inputType="textPassword"
android:nextFocusDown="#+id/email" />
</android.support.design.widget.TextInputLayout>
the problem is, the icon is not appearing, the reason is that of passwordToggleEnabled when I remove it, it shows the drawable
how to show both PasswordToggle Drawable and background drawable?

Use
android:drawableStart="#drawable/ic_launcher_round"
instead of
android:drawableRight="#drawable/ic_launcher_round"
Try this
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_repass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layoutDirection="rtl"
app:hintEnabled="false"
app:passwordToggleEnabled="true">
<EditText
android:id="#+id/repass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="#drawable/ic_launcher_round"
android:hint="nilu"
android:imeOptions="actionNext"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>
NOTE : android:drawableStart="#drawable/ic_launcher_round" is working because of android:layoutDirection="rtl"
OUTPUT

try this
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/rl_main"
android:padding="#dimen/margin_30dp"
android:background="#color/white_color">
<ImageView
android:id="#+id/img_email"
android:layout_width="#dimen/margin_25dp"
android:layout_height="#dimen/margin_25dp"
android:src="#drawable/message"
android:layout_marginTop="#dimen/margin_15dp"
android:layout_alignParentLeft="true"
/>
<!--Email-->
<android.support.design.widget.TextInputLayout
android:id="#+id/til_email_login_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:hint="#string/email"
android:textColorHint="#color/gray">
<com.xxx.app.customeview.CustomFontEditText
android:id="#+id/et_email_login_activity"
style="#style/edit_text_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:text="" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
for password tongle off use app:passwordToggleEnabled="false"

You have to add this line only
android:drawableStart="#drawable/ic_action_rupee"
Use this code It will working for me.
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_repass"
android:layout_width="match_parent"
android:layout_height="37dp"
android:layout_marginTop="10dp"
app:hintEnabled="false"
app:passwordToggleEnabled="true">
<EditText
android:id="#+id/repass"
style="#style/edittexts"
android:drawableStart="#drawable/ic_action_rupee"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/hint_repass"
android:inputType="textPassword"
android:nextFocusDown="#+id/email"
android:drawableLeft="#drawable/ic_action_rupee" />
</android.support.design.widget.TextInputLayout>

Related

EditText TextInputLayout Hint text alignment: Is there a way to align hint text like textAlignment property of EditText view

I have an inputText field(TextInputLayout's EditText) of fixed height.
I want to align hint text to top left of the view.
Problem: hint text is always displayed at center_verticle but I want to display it at top left corner.
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/aboutWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="About Sponsor">
<EditText
android:id="#+id/et_about_sponsor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="250dp"
android:textAlignment="viewStart"
android:layout_centerHorizontal="true"
android:gravity="start|top"
android:imeOptions="actionDone"
android:inputType="textMultiLine|textCapSentences"
android:textColor="#color/white"
android:textColorHint="#color/white"
android:textSize="#dimen/font_medium" />
</com.google.android.material.textfield.TextInputLayout>
As per this github issue you need to set android:minLines to at least 2 along with android:gravity="top".
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/txtInput"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Hint">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/et_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
**android:minLines="2"**
/>
</com.google.android.material.textfield.TextInputLayout>
You can use:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="About Sponsor">
<com.google.android.material.textfield.TextInputEditText
android:minHeight="250dp"
android:textAlignment="viewStart"
android:layout_centerHorizontal="true"
android:gravity="start|top"
android:imeOptions="actionDone"
android:inputType="textMultiLine|textCapSentences"
.../>
</com.google.android.material.textfield.TextInputLayout>
Try to add style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" style to the TextInputLayout
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/aboutWrapper"
android:layout_width="match_parent"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_height="wrap_content"
android:hint="About Sponsor">
<EditText
android:id="#+id/et_about_sponsor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="250dp"
android:textAlignment="viewStart"
android:layout_centerHorizontal="true"
android:gravity="start|top"
android:imeOptions="actionDone"
android:inputType="textMultiLine|textCapSentences"
android:textColor="#color/white"
android:textColorHint="#color/white"
android:textSize="#dimen/font_medium" />
</com.google.android.material.textfield.TextInputLayout>
You can use
<EditText
android:id="#+id/editTextTextPersonName5"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:ems="10"
android:hint="Message"
android:gravity="left|top"
android:inputType="textAutoComplete"
android:textAlignment="textStart" />
Here gravity attribute will help in aligning the text to whichever you want.
You can Refer Here

how to add content inside FieldSetView and legend while generating android layout

I am trying to design a login page in which I am using FieldSetView and legend. The problem is when I am adding text field inside this, the text fields are not added properly. It comes outside
I want the password field inside fieldsetview. Here is the output which I am getting
Here is my activity_main.xml
<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:layout_gravity="center"
android:orientation="vertical"
tools:context=".MainActivity"
>
<libs.mjn.fieldset.FieldSetView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
app:fsv_borderRadius="8dp"
app:fsv_borderColor="#062999"
app:fsv_borderWidth="2dp"
app:fsv_legend="Sign In"
app:fsv_legendPosition="left"
app:fsv_legendSize="16sp">
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlineBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:outlineAmbientShadowColor="#color/colorPrimaryDark"
android:hint="email"
android:text="#string/email"
android:inputType="textEmailAddress"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlineBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="120dp"
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="password"
android:text="#string/password"
android:inputType="textPassword"
/>
</com.google.android.material.textfield.TextInputLayout>
</libs.mjn.fieldset.FieldSetView>
</LinearLayout>
Use LinearLayout like this
<libs.mjn.fieldset.FieldSetView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
app:fsv_borderColor="#062999"
app:fsv_borderRadius="8dp"
app:fsv_borderWidth="2dp"
app:fsv_legend="Sign In"
app:fsv_legendPosition="left"
app:fsv_legendSize="16sp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlineBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="email"
android:inputType="textEmailAddress"
android:outlineAmbientShadowColor="#color/colorPrimaryDark"
android:text="#string/email" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlineBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="120dp">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="password"
android:inputType="textPassword"
android:text="#string/password" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</libs.mjn.fieldset.FieldSetView>

floating hint text not disappear after typing something

i want to make a register fragment with text input layout. But my problem is hint property. when typing, hint's copy goes up. I have two hints when typing.And also I don't have this problem in activity page. How can i solve this in fragment?
https://imgur.com/a/S7evtIO
<android.support.design.widget.TextInputLayout
android:id="#+id/floating_hint_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintTextAppearance="#style/FloatingHintStyle">
<EditText
android:id="#+id/etEmail"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:ems="10"
android:hint="Emailinizi giriniz"
android:inputType="textEmailAddress" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/floating_hint_pass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintEnabled="true"
app:hintTextAppearance="#style/FloatingHintStyle">
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Şifrenizi giriniz"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>
You need to use TextInputEditText instead of EditText, your code should be like
<android.support.design.widget.TextInputLayout
android:id="#+id/floating_hint_email"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="#+id/etEmail"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:ems="10"
android:hint="Emailinizi giriniz"
android:inputType="textEmailAddress" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/floating_hint_pass"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Şifrenizi giriniz"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>

RTL android:hint in TextInputLayout

I have this XML layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:layoutDirection="locale"
android:textDirection="rtl"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".app.storey.view.StoreyInsertFragment">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="somthing"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
I want hint text show on right side but after use layoutDirection,textAlignment still show on left, how can I do this?
I see this link but not solve my problem.
Use android:textAlignment="viewStart" for TextInputEditText field.
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/text_input_user_name"
style="#style/LoginInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginStart="#dimen/margin_editText_end_start"
android:layout_marginTop="#dimen/margin_end_edit_text"
android:layout_marginEnd="#dimen/margin_editText_end_start"
android:layout_marginBottom="#dimen/margin_end_edit_text"
app:hintAnimationEnabled="true"
app:hintEnabled="true"
>
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/edt_user_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center|start"
android:gravity="center|start"
android:textAlignment="center"
android:hint="#string/user_name"
android:inputType="textMultiLine"
android:maxLength="8"
android:padding="20dp"
android:textColor="#color/ches_white"
android:textColorHint="#color/ches_white"
android:textSize="#dimen/text_size_login"/>
<android.support.design.widget.TextInputLayout
android:id="#+id/til_name"
style="#style/TextInputLabel2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dimen_20dp"
android:textColorHint="#color/gray_10"
app:hintEnabled="true"
app:hintTextAppearance="#style/CustomTextAppearance2">
<android.support.v7.widget.AppCompatEditText
android:id="#+id/et_name"
style="#style/EditTextStyleWrap"
android:background="#android:color/transparent"
android:backgroundTint="#color/hint_line"
android:digits="#string/accepted_type"
android:gravity="end"
android:inputType="textPersonName"
android:letterSpacing="0.06"
android:maxLength="50"
android:nextFocusLeft="#+id/et_name"
android:nextFocusUp="#id/et_name"
android:textScaleX="1"
android:hint="name"
android:imeOptions="actionNext"
app:et_font="#{#string/font_sans_regular}"
tools:targetApi="lollipop" />
</android.support.design.widget.TextInputLayout>
If you are using api > 17 then try setting below properties to your EditText
android:textDirection="anyRtl"
android:layoutDirection="rtl"
Also, You need to set hint to your EditText and not your TextInputLayout and set gravity to right as mentioned in other answers.

imeOption="actionNext" not working in TextInputLayout

I am using floating hint from material design. I want to shift focus from one EditText to the next, So I have put imeOptions="actionNext" in all editTexts and imeOptions="actionDone in the last EditText. But focus is not shifting to next EditText.
Below is the snippet of my xml.
<android.support.design.widget.TextInputLayout
android:id="#+id/streetWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/TextInputStyle">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Street/Locality *"
android:imeOptions="actionNext"
android:maxLines="1"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/flatWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_10sdp"
android:theme="#style/TextInputStyle">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Building Name / Flat Number*"
android:imeOptions="actionNext"
android:maxLines="1"/>
</android.support.design.widget.TextInputLayout>
You should add android:imeOptions="actionNext" in EditText section.
<android.support.design.widget.TextInputLayout
android:id="#+id/streetWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/TextInputStyle">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:maxLines="1"
android:inputType="text"/>
</android.support.design.widget.TextInputLayout>
Add attribute android:inputType="text" to your EditText.
Try this:
<android.support.design.widget.TextInputLayout
android:id="#+id/streetWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Street/Locality *"
android:imeOptions="actionNext"
android:maxLines="1"
android:inputType="text"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/flatWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_10sdp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Building Name / Flat Number*"
android:imeOptions="actionNext"
android:maxLines="1"
android:inputType="text"/>
</android.support.design.widget.TextInputLayout>
You should add android:inputType="text" on section Tag
If you not adding inputType imeOption is not work
Try this :
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dimens_16dp">
<android.support.design.widget.TextInputEditText
android:id="#+id/et_impian"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/text_fill_your_dream_here"
android:imeOptions="actionNext"
android:inputType="text"
android:backgroundTint="#color/color_green_manulife"/>
</android.support.design.widget.TextInputLayout>
In my case I had to also add android:nextFocusForward="#id/secondInput". Make sure you are adding id's on TextInputEditText and not on TextInputLayout.
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="First input">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/firstInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="number"
android:nextFocusForward="#id/secondInput">
<requestFocus />
</com.google.android.material.textfield.TextInputEditText>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Second input">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/secondInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:inputType="text"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>

Categories

Resources