TextInputLayout hint left padding [duplicate] - android

This question already has answers here:
Adding a drawableLeft to an EditText shifts the hint towards right, if edittext is inside TextInputlayout
(3 answers)
Closed 6 years ago.
I have added a drawableLeft in and EditText enclosed in TextInputLayout. The position of hint of TextInputLayout is according to the text position(From left i.e. next to drawableLeft) as:
But I want the position of hint as below.
Thank you.

There's no way to currently do this. If you check out the TextInputLayout source, you can see that the hint takes the parent's compound padding into account. The CollapsingTextHelper is not part of the layout's public API, so you can't change its behavior easily.
Your best bet is to change your requirement for this padding or use some sort of custom layout to reach a compromise between effort and effect.

Try below code
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_marginTop="20dp"
android:layout_height="54dp"
android:gravity="bottom"
android:paddingTop="4dp"
android:clipToPadding="false" // above 3 lines are important
android:id="#+id/emailWrapper"
app:hintTextAppearance="#style/floatingLabel">
<EditText
android:layout_width="match_parent"
android:layout_height="54dp"
android:paddingLeft="17dp"
android:paddingRight="17dp"
android:id="#+id/txtEmail"
android:singleLine="true"
android:inputType="textEmailAddress"
android:hint="#string/emailPlaceholder"
android:text="a#a.com"
android:background="#drawable/btn_empty_stroke" />
</android.support.design.widget.TextInputLayout>
Check it also : Android: How to change the textsize in an EditText field?

Related

TextInputEditText - Make clickable but not editable

I have a layout where I want to show a bunvh of edit texts and a date picker. Since I want to have the same design for all fields, I figured out that I need to user an edit text for date picker too but make it non editable but clickable. Below is the xml code of my edit text that will be used to show the date picker :
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/notification_layout"
style="#style/Theme.Connect.InputFieldLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:startIconDrawable="#drawable/ic_stk_notification_24dp">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/notification_edit_text"
style="#style/Theme.Connect.InputField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Notification"
android:maxLines="1"
android:lines="1"
android:cursorVisible="false"/>
</com.google.android.material.textfield.TextInputLayout>
I tried many solutions I found on the internet, I did managed to make edit text non editable but without the ripple click effect. Is there a way to make the edit text non edditable but still keep the ripple click effect? Is this the best practice to show a date picker consisting the design of the form layout?
Try this and change the `android:focusable` attribute to `false`
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/notification_layout"
style="#style/Theme.Connect.InputFieldLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:startIconDrawable="#drawable/ic_stk_notification_24dp">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/notification_edit_text"
style="#style/Theme.Connect.InputField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Notification"
android:maxLines="1"
android:focusable="false"
android:lines="1"
android:cursorVisible="false"/>
</com.google.android.material.textfield.TextInputLayout>
You can simply use a TextView instead of an EditText and you can set an onClickListener() to it. You can also style it the way you want.
notification_textview.setOnClickListener {
// Whatever you want to do after a click
}
You can get a ripple effect on touch by adding these 2 attributes to your textview
<......Textview
android:background=?android:attr/selectableItemBackground
android:clickable="true" />
You can also add styles to a textview that you wanted to use for the editText.

how can i customize an edittext? [duplicate]

This question already has answers here:
Android EditText with different floating label and placeholder
(8 answers)
Closed 2 years ago.
var tel_text = "Enter your phone number"
Consider that the edittext is tel_text with a large font. When the user starts writing this article in edittext, I want it to be animated from bottom to top. How can I customize Edittext the easiest?
It looks like you want to add a hint to it which animates to the top when user begins to type. Wrap it inside TextInputLayout
<android.support.design.widget.TextInputLayout
android:id="#+id/edt_hint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your phone number">
<EditText
android:id="#+id/edit"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>

How to make Android EditText expand vertically when full

I have this EditText
<EditText
android:layout_width="match_parent"
android:layout_height="72dp"
android:hint="#string/write_message"
android:textColorHint="#color/primary_color"
android:ems="10"
android:imeOptions="actionDone"
android:inputType="textImeMultiLine"
android:id="#+id/message_input"
android:layout_gravity="center_horizontal"
android:backgroundTint="#color/primary_color"/>
When the box is filled up with user inputted text, it scrolls to the right to make room for more text, I do not like this behavior, and would prefer it if the EditText box expanded upwards when it needs more room? Is there a way to do this? Thanks.
Yes, this actually involves two things:
Making the EditText accept multi-line input.
Having its height grow as more text lines are added.
Therefore, to achieve this, you need to set up:
android:inputType="textMultiLine"
android:layout_height="wrap_content"
(Be mindful of the difference between textMultiLine and textImeMultiLine).
The full XML snippet would be:
<EditText
android:layout_width="match_parent"
android:inputType="textMultiLine"
android:layout_height="wrap_content"
android:hint="#string/write_message"
android:textColorHint="#color/primary_color"
android:ems="10"
android:imeOptions="actionDone"
android:id="#+id/message_input"
android:layout_gravity="center_horizontal"
android:backgroundTint="#color/primary_color"/>
Use both flags: textMultiLine will wrap your input, and textImeMultiLine will provide a break-line key in your keyboard.
<EditText
...
android:layout_height="wrap_content"
android:inputType="textImeMultiLine|textMultiLine"
... />
In my case I have multiline text, but it showed one line and a keyboard:
Though I have already set android:inputType="textCapSentences|textAutoCorrect|textMultiLine", it didn't help. Then I understood that when the keyboard appears in DialogFragment, it collapses the EditText. See DialogFragment and force to show keyboard to show keyboard when DialogFragment shows.
Then I added a short delay (100-300 ms) before showing the keyboard. Now I have:
In AndroidManifest I set android:windowSoftInputMode="adjustResize" for current activity.

MultiLine EditText in Android with the cursor starting on top [duplicate]

This question already has an answer here:
Changing where cursor starts in an expanded EditText
(1 answer)
Closed 9 years ago.
I know it seems it's an already thousand times answered issue but I haven't found anything that works for me.
I have a MultiLine EditText on Android that adapts to the view size by "playing" with the weight (1) and the height (0dip). I am using gravity "top" but it starts in the middle.
I guess the problem it's related with the weight. Here's the code (the parent is a LinearLayout):
<EditText
android:id="#+id/txtContacto"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_gravity="top"
android:inputType="textMultiLine"
android:weight="1">
</EditText>
<EditText
android:id="#+id/txtContacto"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:gravity="top"
android:inputType="textMultiLine"
android:weight="1">
</EditText>
try the above code.. where layout gravity sets the edittext and gravity sets the content of edittext.

Padding for hint text inside EditText

I want to be able to add padding to the text that is displayed inside the EditText, using
android:hint="some text"
If I only add padding for the EditText regularly, it adds the padding for the whole view. And i want it for the text that gives a hint for the user, what needs to be entered. If someone knows how to do this, please give me a feedback.
You may find your solution in this answer:
EditText set text start 10dp from left border
It helped me to achieve the padding for hint in username field:
<EditText
android:id="#+id/txtUsername"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:background="#drawable/bkg_login_txt_usuario"
android:hint="#string/hint_username"
android:paddingLeft="10dp"
android:singleLine="true" >
<requestFocus />
</EditText>
I hope this helps.
You can use android:drawablePadding which denotes the padding between the drawable and the hint texts.
Use the TextChangedListener and a TextWatcher to monitor the text inside the EditText. Use the TextWatcher check to see if the EditText is empty and set the padding, otherwise remove the padding.

Categories

Resources