Button should be sticky at Bottom with adjustResize - android

I want to have a button that should be sticky at the bottom when Keyboard is open.
Linear layout with a long-form that contains multiple edittext in the vertical orientation.
Button is at the bottom and outside of scrollview
Manifest has a adjustsize property
So when I click any of the edit text, the Button comes up on the top of the Keyboard.
I have even tried android:fitsToSystemWindow=true but nothing works
I want something like that where the button does not come up on the keyboard and button should be sticky at the bottom too. How can I achieve that ?
Here is my XML file
<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:layout_width="match_parent"
android:layout_height="match_parent" tools:context=".items.ui.AddEditItemFragment">
<ScrollView android:id="#+id/sv_add_edit_item" android:layout_width="match_parent"
android:layout_height="0dp" app:layout_constraintBottom_toTopOf="#+id/btn_save"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/itemNameInputLayout" android:layout_width="match_parent"
android:layout_height="wrap_content" android:background="#color/white"
android:padding="#dimen/default_margin_padding" app:errorEnabled="true"
app:errorTextAppearance="#style/ErrorText" app:hintTextAppearance="#style/HintText">
<com.google.android.material.textfield.TextInputEditText
style="#style/editTextInputLayout" android:layout_width="match_parent"
android:layout_height="wrap_content" android:inputType="textCapWords"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/itemNameInputLayout" android:layout_width="match_parent"
android:layout_height="wrap_content" android:background="#color/white"
android:padding="#dimen/default_margin_padding" app:errorEnabled="true"
app:errorTextAppearance="#style/ErrorText" app:hintTextAppearance="#style/HintText">
<com.google.android.material.textfield.TextInputEditText
style="#style/editTextInputLayout" android:layout_width="match_parent"
android:layout_height="wrap_content" android:inputType="textCapWords"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/itemNameInputLayout" android:layout_width="match_parent"
android:layout_height="wrap_content" android:background="#color/white"
android:padding="#dimen/default_margin_padding" app:errorEnabled="true"
app:errorTextAppearance="#style/ErrorText" app:hintTextAppearance="#style/HintText">
<com.google.android.material.textfield.TextInputEditText
style="#style/editTextInputLayout" android:layout_width="match_parent"
android:layout_height="wrap_content" android:inputType="textCapWords"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/itemNameInputLayout" android:layout_width="match_parent"
android:layout_height="wrap_content" android:background="#color/white"
android:padding="#dimen/default_margin_padding" app:errorEnabled="true"
app:errorTextAppearance="#style/ErrorText" app:hintTextAppearance="#style/HintText">
<com.google.android.material.textfield.TextInputEditText
style="#style/editTextInputLayout" android:layout_width="match_parent"
android:layout_height="wrap_content" android:inputType="textCapWords"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/itemNameInputLayout" android:layout_width="match_parent"
android:layout_height="wrap_content" android:background="#color/white"
android:padding="#dimen/default_margin_padding" app:errorEnabled="true"
app:errorTextAppearance="#style/ErrorText" app:hintTextAppearance="#style/HintText">
<com.google.android.material.textfield.TextInputEditText
style="#style/editTextInputLayout" android:layout_width="match_parent"
android:layout_height="wrap_content" android:inputType="textCapWords"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/itemNameInputLayout" android:layout_width="match_parent"
android:layout_height="wrap_content" android:background="#color/white"
android:padding="#dimen/default_margin_padding" app:errorEnabled="true"
app:errorTextAppearance="#style/ErrorText" app:hintTextAppearance="#style/HintText">
<com.google.android.material.textfield.TextInputEditText
style="#style/editTextInputLayout" android:layout_width="match_parent"
android:layout_height="wrap_content" android:inputType="textCapWords"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/itemNameInputLayout" android:layout_width="match_parent"
android:layout_height="wrap_content" android:background="#color/white"
android:padding="#dimen/default_margin_padding" app:errorEnabled="true"
app:errorTextAppearance="#style/ErrorText" app:hintTextAppearance="#style/HintText">
<com.google.android.material.textfield.TextInputEditText
style="#style/editTextInputLayout" android:layout_width="match_parent"
android:layout_height="wrap_content" android:inputType="textCapWords"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</ScrollView>
<Button android:id="#+id/btn_save" style="#style/buttonThemeColor"
android:layout_width="match_parent" android:text="#string/save"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>```
Any help will be appreciated

One way can be to add global listener to detect whether keyboard is showing or not. And then hide/show your button accordingly.
You can take help from my this answer for the same.

In your menifest file use adjustPan for windowSoftInputMode rather then adjustResize
<activity android:name=".youractivity"
android:windowSoftInputMode="adjustPan" />

Related

EditText not showing the hint or the outline box until focused

I saw that there are numerous threads raised on this topic but none of them seems to solve my issue.
I have an EditText inside of InputLayout and it shows blank until focused.
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_marginTop="20dp"
>
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/etInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:hint="Name"/>
Android version 12
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
app:hintTextColor="#color/black"
app:boxStrokeColor="#color/black"
android:layout_marginTop="20dp"
app:boxStrokeWidth="2dp"
android:textColorHint="#color/black"
>
<EditText
android:id="#+id/etInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/black"
/>
</com.google.android.material.textfield.TextInputLayout>

trying to align a view vertically to the edit text inside the inputlayout [see image] the helper text shifts the alignment

just look how the OTP button seems to not be aligned properly. how do I fix that?
I'm using material UI's outlined textfeild which also has a helper text. That adds to the height of the input layout. hence, this issue. I want the OTP button to be aligned perfectly besides the text field. is there a way to do that other than making the helper text into a textview? I also don't want to use margin on the button to align it because that can cause unexpected changes in different screen sizes. Here's the code -
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView
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="wrap_content"
android:layout_margin="#dimen/login_card_spacing"
app:cardBackgroundColor="#eeeeee"
app:cardCornerRadius="#dimen/login_card_spacing">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/sign_up_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/login_card_spacing"
android:text="SIGN UP"
android:textSize="#dimen/huge_text_size"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/user_name_edit_text"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/login_card_spacing"
android:hint="User Name"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/sign_up_label">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/user_password_edit_text"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/login_card_spacing"
android:hint="Set New User Password"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/user_name_edit_text">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/user_phone_number_edit_text"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/login_card_spacing"
android:hint="Phone Number"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/user_password_edit_text">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/user_otp_edit_text"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/login_card_spacing"
android:layout_marginEnd="#dimen/login_card_spacing"
android:hint="OTP Generated"
app:helperText="Check Message Box For The Entered Phone Number"
app:layout_constraintLeft_toLeftOf="#id/user_name_edit_text"
app:layout_constraintRight_toLeftOf="#id/otp_generator"
app:layout_constraintTop_toBottomOf="#id/user_phone_number_edit_text">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="#+id/otp_generator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="otp"
app:layout_constraintBottom_toBottomOf="#id/user_otp_edit_text"
app:layout_constraintRight_toRightOf="#id/user_name_edit_text"
app:layout_constraintTop_toTopOf="#id/user_otp_edit_text" />
<Button
android:id="#+id/cancel_login"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginVertical="#dimen/login_card_spacing"
android:layout_marginEnd="#dimen/login_card_spacing"
android:text="cancel"
style="?attr/materialButtonOutlinedStyle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="#id/user_name_edit_text"
app:layout_constraintRight_toLeftOf="#id/register_login"
app:layout_constraintTop_toBottomOf="#id/user_otp_edit_text" />
<Button
android:id="#+id/register_login"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/login_card_spacing"
android:text="register"
app:layout_constraintBottom_toBottomOf="#id/cancel_login"
app:layout_constraintLeft_toRightOf="#id/cancel_login"
app:layout_constraintRight_toRightOf="#id/user_name_edit_text"
app:layout_constraintTop_toTopOf="#id/cancel_login" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>

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>

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.

TextInputLayout setCounterEnables doesn't work - Android

I have a layout with a TextInputLayouts elements and I want to enable counter of characters. The problem is it's not working and I can't see the counter when I run the app.
Here is my layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="match_parent"
android:background="#color/colorBackground"
android:paddingLeft="#dimen/create_step_padding"
android:paddingRight="#dimen/create_step_padding"
android:paddingTop="#dimen/create_step_padding">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Shipper Text Area-->
<android.support.design.widget.TextInputLayout
android:id="#+id/shipper_layout"
android:layout_width="0dp"
android:layout_height="110dp"
android:background="#drawable/text_area_background"
android:paddingEnd="#dimen/text_input_layout_side_padding"
android:paddingStart="#dimen/text_input_layout_side_padding"
android:paddingTop="#dimen/text_input_layout_top_padding"
app:counterEnabled="true"
app:hintTextAppearance="#style/HintTextStyle"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.design.widget.TextInputEditText
android:id="#+id/shipper_field"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#null"
android:gravity="top|start"
android:hint="#string/shipper_field"
android:inputType="textMultiLine"
android:lines="5"
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical" />
</android.support.design.widget.TextInputLayout>
<!-- Consignee Text Area-->
<android.support.design.widget.TextInputLayout
android:id="#+id/consignee_layout"
android:layout_width="0dp"
android:layout_height="110dp"
android:layout_marginTop="16dp"
android:background="#drawable/text_area_background"
android:paddingLeft="#dimen/text_input_layout_side_padding"
android:paddingTop="#dimen/text_input_layout_top_padding"
app:counterEnabled="true"
app:hintTextAppearance="#style/HintTextStyle"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/shipper_layout">
<android.support.design.widget.TextInputEditText
android:id="#+id/consignee_field"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#null"
android:gravity="top|start"
android:hint="#string/consignee_field"
android:inputType="textMultiLine"
android:lines="5"
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical" />
</android.support.design.widget.TextInputLayout>
<!-- Airport of Departure -->
<!-- Airport of Destination -->
<com.silverfix.dgdeditor.utils.views.AirportAutoCompleteEditText
android:id="#+id/aodep_field"
android:layout_width="217dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintBottom_toBottomOf="#+id/textView11"
app:layout_constraintHorizontal_bias="0.512"
app:layout_constraintLeft_toRightOf="#+id/textView11"
app:layout_constraintRight_toRightOf="parent" />
<com.silverfix.dgdeditor.utils.views.AirportAutoCompleteEditText
android:id="#+id/aodes_field"
android:layout_width="217dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintBottom_toBottomOf="#+id/textView12"
app:layout_constraintLeft_toLeftOf="#+id/aodep_field" />
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:text="#string/aodep_field"
android:textAppearance="#style/DefaultTextStyle"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/consignee_layout" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="#string/aodes_field"
android:textAppearance="#style/DefaultTextStyle"
app:layout_constraintLeft_toLeftOf="#+id/textView11"
app:layout_constraintTop_toBottomOf="#+id/textView11" />
</android.support.constraint.ConstraintLayout>
</ScrollView>
As you can see, I enabled app:counterEnabled in the TextInputLayouts.
Then I try to set the max chars inside my code.
Here is the code:
shipperTextArea = (TextInputLayout) rootView.findViewById(R.id.shipper_layout);
consigneeTextArea = (TextInputLayout) rootView.findViewById(R.id.consignee_layout);
shipperTextArea.setCounterMaxLength(60);
consigneeTextArea.setCounterMaxLength(60);
just set the counter in xml files, add this:
<android.support.design.widget.TextInputLayout
app:counterMaxLength="60"
app:counterEnabled="true"
i think that don't need to set in the java class.

Categories

Resources