How can I change the position of the hint in an editText? - android

I want to align my second hint(email) to match the position of the first one(nickname), and I can't seem to do it.
Please check my layout from this link
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="347dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColorHint="#000000"
app:counterEnabled="true"
app:counterMaxLength="20"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.32999998">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/nickname"
android:maxLength="21"
/>
</com.google.android.material.textfield.TextInputLayout>
<EditText
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:id="#+id/editTextTextEmailAddress"
android:layout_width="342dp"
android:layout_height="70dp"
android:layout_marginTop="31dp"
android:ems="10"
android:inputType="textEmailAddress"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.463"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout"
app:layout_constraintVertical_bias="0.062"
android:hint="#string/prompt_email"
android:textColorHint="#000000"
/>
please note that I am a beginner in android, so take it easy on me.

Related

layout_constraintHorizontal_weight = 1 in ConstraintLayout is not Working

TextInputEditText in TextInputLayout equal width in ConstraintLayout using wight property. used layout_constraintHorizontal_weight = 1 is not work.how to give same width using weight property to Textinputlayout. This is give below result.
I want to below result :
xml code is :
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tilFirstName1"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
app:layout_constraintHorizontal_weight="1"
app:boxBackgroundMode="outline"
app:endIconMode="clear_text"
app:hintEnabled="false"
app:layout_constraintEnd_toStartOf="#+id/tilLastName1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/etFirstName1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/custom_edittext_input"
android:hint="First Name"
android:inputType="textPersonName" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tilLastName1"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="32dp"
app:boxBackgroundMode="outline"
app:endIconMode="clear_text"
app:hintEnabled="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/etLastName1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/custom_edittext_input"
android:hint="Last Name"
android:inputType="textPersonName" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
I made a few modifications to your code to end up with this. The trick it to constrain the end of the first firstName1 to the start of lastName1 and do the opposite for lastName1 and distribute the margins between them at the boundary.
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tilFirstName1"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="8dp"
app:boxBackgroundMode="outline"
app:endIconMode="clear_text"
app:hintEnabled="false"
app:layout_constraintEnd_toStartOf="#+id/tilLastName1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/etFirstName1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/custom_edittext_input"
android:hint="First Name"
android:inputType="textPersonName" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tilLastName1"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="8dp"
app:boxBackgroundMode="outline"
app:endIconMode="clear_text"
app:hintEnabled="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/tilFirstName1"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/etLastName1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/custom_edittext_input"
android:hint="Last Name"
android:inputType="textPersonName" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Espressomatch ExposedDropdownMenu

how to match ExposedDropdownMenu from espresso , I want the first item , but onview nor ondata work
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textField_driver_title"
style="#style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:hint="#string/driver_title_hint"
android:textColorHint="#color/brown_grey"
app:boxBackgroundColor="#color/white"
app:errorEnabled="true"
app:hintTextColor="#color/brown_grey"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<AutoCompleteTextView
android:id="#+id/editText_driver_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"
android:lines="1" />
</com.google.android.material.textfield.TextInputLayout>

Set hint on top of TextInputEditText in TextInputLayout

How to set hint of TextInputEditText on top of view.
I have the following edit text that user will type description of the product, but hint is on center of view.
Here is the XML code.
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/interestDescriptionView"
style="#style/TextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:maxLines="5"
app:layout_constraintBottom_toTopOf="#+id/tagsView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/titleView"
app:layout_constraintVertical_chainStyle="packed">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/interestDescriptionEditTextView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:textAlignment="viewStart"
android:hint="Descrição *"
android:layout_centerHorizontal="true"
android:gravity="start|top"
android:imeOptions="actionDone"
android:inputType="textMultiLine|textCapSentences"
android:importantForAutofill="no" />
</com.google.android.material.textfield.TextInputLayout>
You can set android:minLines to 2 or greater .. this will make it work
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/interestDescriptionView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Descrição *"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textview"
app:layout_constraintVertical_chainStyle="packed">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/interestDescriptionEditTextView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:gravity="top"
android:imeOptions="actionDone"
android:importantForAutofill="no"
android:inputType="textMultiLine|textCapSentences"
android:maxLines="5"
android:minLines="2"
android:textAlignment="viewStart" />
</com.google.android.material.textfield.TextInputLayout>
Also you can check other workarounds from here

How to get material edit text in UiAutomator test

I have TextInputLayout in my layout
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/email_text_input"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="0dp"
app:errorEnabled="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/editTextEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/email_address"
android:inputType="textWebEmailAddress"
android:text=""
android:textColor="#color/white" />
</com.google.android.material.textfield.TextInputLayout>
and I set error to email_text_input
email_text_input.error = getString(R.string.please_enter_a_valid_email)
How can i check if error is shown in my UiAutomated tests?

Password Type Default Unmask

I am using Android TextInputLayout with password type. I see a mask/unmask icon. How can I set the text to unmasked by default?
<android.support.design.widget.TextInputLayout
android:id="#+id/textInputLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout"
app:passwordToggleEnabled="true"
app:theme="#style/EditTextMaterialTheme">
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textVisiblePassword"
android:maxLines="1"
android:singleLine="true"
android:text=""
android:textColorLink="#android:color/darker_gray" />
</android.support.design.widget.TextInputLayout>
// When you define your edittext in oncreate method, that time put below line
youreditText.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
Your XML should be like this
<android.support.design.widget.TextInputLayout
android:id="#+id/textInputLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:passwordToggleEnabled="true"
app:theme="#style/EditTextMaterialTheme">
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true"
android:text=""
android:textColorLink="#android:color/darker_gray" />
</android.support.design.widget.TextInputLayout>
And in your java class write these lines
TextInputLayout textInputLayout = findViewById(R.id.textInputLayout2);
textInputLayout.passwordVisibilityToggleRequested(true);

Categories

Resources