TextInputLayout hint padding not working - android

I want to give padding to hint of edittext in TextInputLayout
where email address is hint and Sample is text
also tried this solution but didn't work.
facing this issue after changing support design library 23.1.0
here is my code
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp">
<android.support.v7.widget.AppCompatEditText
android:id="#+id/edtEmailAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/border_round_edt_grey"
android:focusableInTouchMode="true"
android:hint="#string/emailadd"
android:padding="10dp"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>

As per this answer ,if you have custom background set on EditText the android:padding attribute simple doesn't work to alter the spacing b/w the hint text and edit text .So if you have set custom background to your AppCompatEditText, you can use android:translationY attribute in the AppCompatEditText
Please add below line in your AppCompatEditText.
android:translationY="10dp"
hope you got your answer :)

Related

Android set padding for hint text

Is it possible to set the padding for the hint inside an EditText in Android?
Cannot seem to find any documentation in regards.
Try following code:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/email"
android:hint="Hint Text"
android:paddingStart="15dp"
/>
You cannot add padding to hint text only. but you can apply padding for both hint and text using paddingStart attribute.
android:paddingStart="16dp"

TextInputLayout boxBackgroundColor not working after 'com.google.android.material:material:1.1.0-alpha02'

The problem I have is when I want to set boxBackgroundColor on TextInputLayout on versions after'com.google.android.material:material:1.1.0-alpha02' of design library I don't see any changes and since I want to use ExposedDropdownMenu which is only supported in later versions, I can't seem to find any solutions.
I've tried setting it in java and also in styles but no results.
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/Theme.MaterialComponents"
app:boxBackgroundColor="#color/colorAccent"
android:hint="#string/hint_text">
<AutoCompleteTextView
android:id="#+id/filled_exposed_dropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
Check the doc:
Note: When using a filled text field with an EditText child that is not a
TextInputEditText, make sure to set the EditText's android:background to
#null. This allows TextInputLayout to set a filled background on the
EditText.
Just use:
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
app:boxBackgroundColor="#color/primaryLightColor"
...>
<AutoCompleteTextView
android:background="#null"
.../>
</com.google.android.material.textfield.TextInputLayout>

TextInputLayout not showing hint text fully

I'm using recently released Android Design Support Library to show floating label with EditTexts. But I'm facing the problem that the Hint text is max hint text does not show fully it show ..... on rest of words.
My Layout is as follows:
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:textColorHint="#android:color/black"
app:hintTextAppearance="#style/TextAppearence.App.TextInputLayout">
<EditText
android:id="#+id/et_test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:imeOptions="actionNext"
android:inputType="text"
android:lines="1"
android:textColor="#android:color/black"
android:textColorHint="#android:color/black"
android:textSize="#dimen/et_font_size"
android:theme="#style/MYAppTheme"/>
</android.support.design.widget.TextInputLayout>
Currently showing like this.
I'm using recently released Android Design Support Library to show floating label with EditTexts. But I'm facing the problem that the Hint text is max hint text does not show fully it show
AFAIK it is not possible to add MultiLine hint in TextInputLayout

Android floating label effect no working on TextInputLayout using databinding

The hint wont float if u set it using data binding
<android.support.design.widget.TextInputLayout
android:id="#+id/inputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:theme="#style/TextAppearance.TextInputLayout.Form"
>
<EditText
android:id="#+id/usernameEditTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/default_margin_3"
android:textSize="16sp"
android:singleLine="true"
android:hint="#{model.label}"
android:inputType="none"
/>
</android.support.design.widget.TextInputLayout>
But if u set the hint manually, it works.
Im using Android Studio 3.0
Also using kapt "com.android.databinding:compiler:2.3.3"
Anyone solved this one?
You have to set the hint attribute on the TextInputLayout.
With Material Components:
<com.google.android.material.textfield.TextInputLayout
android:hint="#{viewModel.textHint}"
with old support library:
<android.support.design.widget.TextInputLayout
android:hint="#{....}"
The reason is that TextInputLayout reads the hint attribute from the TextInputEditText only once (if not specified). After the inflation the changes on the TextInputEditText don't change the TextInputLayout's hint.
With the databinding on the TextInputEditText you are not updating the TextInputLayout for the same reason.

How do I center the hint text within an EditText in Android?

I need to center the Hint text within an EditText in Android. How do I do this?
In order for centering of hint text to work with EditText you have to make sure android:ellipsize="start" is defined. I don't know why this makes it work, but it does.
Example pulled from personal code:
<EditText
android:id="#+id/player2Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:ellipsize="start"
android:gravity="center_horizontal"
android:hint="#string/player2_name"
android:inputType="textCapWords|textPersonName"
android:singleLine="true" />
Actually, android:gravity="center_horizontal" creates the centering effect you're looking for. Similarly, you can use android:gravity="start" to put hint text at the beginning of the EditText view, and so on.
Use this xml attribute:
android:gravity="center"
use attribute
android:gravity="center"
I used this code in every circumstances, and it works perfectly without using android:ellipsize="start" to make a hint in center.
<EditText
android:id="#+id/player2Name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:hint="robi"
android:inputType="text" />
I think the answer should be :
android:textAlignment="center"
textAlignment worked for me.
textAlignment="center"
Unfortunately, neither answer helped me aligning hint, written in LTR language, while the layout orientation was RTL. I needed such layout in a kind of translation application to make overlay icons not interfere with RTL text. But this trick didn't work with hints while there was no any text yet (icons appeared above the hint) and I came to the following java solution to layout problem:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
. . .
if (isRightToLeft()){
EditText guess = (EditText) rootView.findViewById(android.R.id.text1);
CharSequence hint = "\u200F" + guess.getHint();
guess.setHint(hint);
}
. . .
}
The trick was in right-to-left mark to prepend a left-to-right string. And it seems to work, but does anyone know a more elegant solution?
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="ENTER PIN"
android:inputType="numberPassword" />
</android.support.design.widget.TextInputLayout>
Note: in the tag TextInputEditText,the property
android:gravity="center"
is what makes the deal of aligning the text in the center including the hint text
use this: android:gravity="center"
I use this and worked for me
android:gravity="Left|center_vertical"
use android:textAlignment="center" in EditText , it work for me
This worked for me:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/nombreslayoutinput">
<EditText
android:id="#+id/nombreslayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/nombres"
android:layout_centerInParent="true"
android:gravity="center|center_vertical"
android:ellipsize="start"
android:inputType="textCapWords|textPersonName"
/>
</android.support.design.widget.TextInputLayout>
The correct answer is
android:gravity="center_horizontal
hint gravity
android:textAlignment="center"
text gravity
android:gravity="left"
My problem was that the EditText wasn't big enought to fit exactly inside its parent (FrameLayout in my case), so using just android:gravity="center" (center_vertical, horizontal, start, or whatever) would just fit it inside the EditText, and not in its parent, so I had to center the EditText inside its parent using:
android:layout_gravity="center"
pd: I used android:background="#android:color/transparent" to hide the ugly underline in the EditText hint

Categories

Resources