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

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>

Related

Add hint text at the below of the input field

At the moment, I have the simplest one-page application with one data entry field. I looked at a lot of examples, but I could not find the answer to my question: how do I add hint text at the bottom of the input field?
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:id="#+id/editTextUserId"
android:layout_width="347dp"
android:layout_height="60dp"
android:layout_marginBottom="20dp"
android:ems="10"
android:hint="User"
android:inputType="textPersonName"
android:text="#string/user_id"
android:textSize="16sp"
app:layout_constraintBottom_toTopOf="#+id/imageButton"
app:layout_constraintEnd_toEndOf="#+id/editTextDeviveId"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="#+id/editTextSessionId"
app:layout_constraintTop_toBottomOf="#+id/editTextDeviveId"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/til_customer_no"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="3dp"
app:helperTextEnabled="true"
app:helperText="User">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/editTextUserId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Customer No"
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
Add a Textview and Constrain it below your Edittext
<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=".MainActivity">
<EditText
android:id="#+id/editTextUserId"
android:layout_width="347dp"
android:layout_height="60dp"
android:layout_marginBottom="20dp"
android:ems="10"
android:hint="User"
android:inputType="textPersonName"
android:text="#string/user_id"
android:textSize="16sp"
app:layout_constraintBottom_toTopOf="#+id/imageButton"
app:layout_constraintEnd_toEndOf="#+id/editTextDeviveId"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="#+id/editTextSessionId"
app:layout_constraintTop_toBottomOf="#+id/editTextDeviveId"
/>
<TextView
android:id="#+id/hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:text="user"
android:textColor="#android:color/holo_red_dark"
android:textSize="14sp"
app:layout_constraintStart_toStartOf="#+id/editTextUserId"
app:layout_constraintTop_toBottomOf="#+id/editTextUserId" />
</androidx.constraintlayout.widget.ConstraintLayout>
Then if you want to show/hide it base on user interaction you can do something
like this in your activity
editTextUserId.setOnFocusChangeListener((view, b) -> {
if(b){hint.setVisibility(View.VISIBLE);}
else {hint.setVisibility(View.INVISIBLE);}
});

Adjust view height to remove extra spaces in a constraint layout

Here, is how my screen looks like
Login screen
I want to remove extra spaces between the submit button and the bottom of the screen.
I researched about this issue in SO. But exactly no one answers it as far I have looked.
Can you suggest some ways to do so?
I have attached the XML layout below for reference.
Login layout
<?xml version="1.0" encoding="utf-8"?>
<layout>
<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"
android:background="#color/colorAccent"
tools:context=".MainActivity">
<View
android:id="#+id/view_form"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintVertical_weight="0.50"
android:layout_marginTop="#dimen/marginTopLogin"
android:background="#drawable/round_cornered_top_white_bg_drawable"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<EditText
android:id="#+id/etUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:autofillHints="name"
android:hint="Username"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1"
android:padding="16dp"
app:layout_constraintEnd_toEndOf="#id/view_form"
app:layout_constraintStart_toStartOf="#id/view_form"
app:layout_constraintTop_toTopOf="#+id/view_form" />
<EditText
android:id="#+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:autofillHints="password"
android:hint="Password"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:maxLines="1"
android:padding="16dp"
app:layout_constraintEnd_toEndOf="#id/view_form"
app:layout_constraintStart_toStartOf="#id/view_form"
app:layout_constraintTop_toBottomOf="#+id/etUsername"/>
<CheckBox
android:id="#+id/imgTogglePassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-5dp"
android:layout_marginEnd="-5dp"
android:button="#drawable/btn_toggle_password"
android:padding="16dp"
app:layout_constraintBottom_toBottomOf="#id/etPassword"
app:layout_constraintEnd_toEndOf="#id/etPassword"
app:layout_constraintTop_toTopOf="#id/etPassword" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_marginTop="20dp"
android:background="#color/colorAccent"
app:layout_constraintTop_toBottomOf="#id/etPassword"
app:layout_constraintStart_toStartOf="#id/view_form"
app:layout_constraintEnd_toEndOf="#id/view_form"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
try it
<layout>
<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"
android:background="#color/colorAccent"
tools:context=".MainActivity">
<View
android:id="#+id/view_form"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="#dimen/marginTopLogin"
android:background="#drawable/round_cornered_top_white_bg_drawable"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_weight="0.50" />
<EditText
android:id="#+id/etUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:autofillHints="name"
android:hint="Username"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1"
android:padding="16dp"
app:layout_constraintEnd_toEndOf="#id/view_form"
app:layout_constraintStart_toStartOf="#id/view_form"
app:layout_constraintTop_toTopOf="#+id/view_form" />
<EditText
android:id="#+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:autofillHints="password"
android:hint="Password"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:maxLines="1"
android:padding="16dp"
app:layout_constraintEnd_toEndOf="#id/view_form"
app:layout_constraintStart_toStartOf="#id/view_form"
app:layout_constraintTop_toBottomOf="#+id/etUsername" />
<CheckBox
android:id="#+id/imgTogglePassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-5dp"
android:layout_marginEnd="-5dp"
android:button="#drawable/btn_toggle_password"
android:padding="16dp"
app:layout_constraintBottom_toBottomOf="#id/etPassword"
app:layout_constraintEnd_toEndOf="#id/etPassword"
app:layout_constraintTop_toTopOf="#id/etPassword" />
<androidx.appcompat.widget.AppCompatButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:text="Submit"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

Scroll view when soft keyboard is up in fragment with Toolbar and windowTranslucentStatus set to true

Fragment is not scrolling when keyboard is up, meanwhile similar setup has work for activities. I added android:windowSoftInputMode="adjustResize|stateAlwaysHidden in the activity that is hosting the fragment, and added android:fitsSystemWindows="true" to the root layout of the fragment. I'm using Butterknife tho. Here are the code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="#drawable/bg_create_account">
<View
android:id="#+id/vail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black_two" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_gravity="center"
android:background="#color/black"
android:gravity="center_horizontal"
android:paddingTop="#dimen/status_bar_height">
<TextView
style="#style/ProximaNova18PtWhite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:lineSpacingExtra="4sp"
android:text="#string/create_account"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="16sp" />
</androidx.appcompat.widget.Toolbar>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:id="#+id/inner_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/username_layout"
style="#style/LoginTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/content_margin"
android:layout_marginEnd="#dimen/content_margin"
android:hint="#string/username"
app:hintAnimationEnabled="true"
app:hintTextAppearance="#style/ProximaNova14Pt"
app:hintTextColor="#color/white">
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/username_edit"
style="#style/LoginEdittextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:importantForAutofill="noExcludeDescendants"
android:inputType="textEmailAddress"
android:textColorHint="#color/white"
tools:text="dewe" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/email_layout"
style="#style/LoginTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/content_margin"
android:layout_marginTop="20dp"
android:layout_marginEnd="#dimen/content_margin"
android:hint="#string/email"
app:hintAnimationEnabled="true"
app:hintTextAppearance="#style/ProximaNova14Pt"
app:hintTextColor="#color/white">
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/email_edit"
style="#style/LoginEdittextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:importantForAutofill="noExcludeDescendants"
android:inputType="textEmailAddress"
android:textColorHint="#color/white"
tools:text="dewe" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/password_layout"
style="#style/LoginTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/content_margin"
android:layout_marginTop="20dp"
android:layout_marginEnd="#dimen/content_margin"
android:hint="#string/password"
app:hintAnimationEnabled="true"
app:hintTextAppearance="#style/ProximaNova14Pt"
app:hintTextColor="#color/white">
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/password_edit"
style="#style/LoginEdittextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:importantForAutofill="noExcludeDescendants"
android:inputType="textPassword"
android:textColorHint="#color/white"
tools:text="dewe" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/confirm_password_layout"
style="#style/LoginTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/content_margin"
android:layout_marginTop="20dp"
android:layout_marginEnd="#dimen/content_margin"
android:hint="#string/confirm_password"
app:hintAnimationEnabled="true"
app:hintTextAppearance="#style/ProximaNova14Pt"
app:hintTextColor="#color/white">
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/confirm_password_edit"
style="#style/LoginEdittextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:importantForAutofill="noExcludeDescendants"
android:inputType="textPassword"
android:textColorHint="#color/white"
tools:text="dewe" />
</com.google.android.material.textfield.TextInputLayout>
<androidx.appcompat.widget.AppCompatCheckBox
android:id="#+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginStart="#dimen/content_margin"
android:layout_marginTop="40dp"
android:layout_marginEnd="#dimen/content_margin"
android:checked="true"
android:hint="#string/i_agree_to_all_the_terms_and_conditions"
android:padding="0dp"
android:textAppearance="#style/ProximaNova14Pt"
android:textColorHint="#color/white"
app:buttonTint="#color/white" />
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/create_account_button"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginStart="#dimen/content_margin"
android:layout_marginTop="40dp"
android:layout_marginEnd="#dimen/content_margin"
android:background="#drawable/bg_login_button"
android:fontFamily="#font/proxima_nova_regular"
android:lineSpacingExtra="4sp"
android:text="#string/create_account_button"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="18sp" />
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<FrameLayout
android:id="#+id/terms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#drawable/text_view_button_selector"
android:layout_marginBottom="#dimen/default_margin"
android:padding="#dimen/default_margin_half">
<TextView
style="#style/ProximaNova14Pt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/view_terms_and_conditions" />
</FrameLayout>
<View
android:id="#+id/stub"
android:layout_width="match_parent"
android:layout_height="56dp"
android:visibility="gone" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
</FrameLayout>
Here's an except from the manifest:
<activity
android:name=".view.EntranceActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.Launcher"
android:windowSoftInputMode="adjustResize|stateAlwaysHidden" />
And the Activity that host the fragment:
#Layout(R.layout.activity_entrance)
public class EntranceActivity extends BaseActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
router.newRootScreen(new Screens.LoginScreen());
}
#Override
protected void callInjections() {
injection().inject(this);
}
After I removed this line from the activity that host the fragment, it works:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
This was setting the fullscreen mode, and thus prevent adjustResize from working

Button should be sticky at Bottom with adjustResize

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" />

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