TextInputLayout does not show hint in Edit Text [duplicate] - android

This question already has answers here:
TextInputLayout not showing EditText hint before user focus on it
(17 answers)
Closed 7 years ago.
Below is the code that I am using. TextInputLayout is included as a part of Androids new Design library. But it does show the hint inside of the EditText. Am I using this the wrong way?
Once I click on the EditText the hint text animation works properly. Also when I click on some other EditText the hint text returns properly. So that is also not an issue. But I am not able to view the hint text in the first place.
<android.support.design.widget.TextInputLayout
android:id="#+id/tilDrugName"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/edtDrugName"
style="#style/ETPrescription"
android:hint="#string/drug_name"/>
</android.support.design.widget.TextInputLayout>

As far as I have come across, this has been a bug in Android Support library for design.
Android Source Bug
So I think this will be resolved in upcoming updates.

Related

android - edittext keyboard not showing

I am creating an edittext programmatically. But I was not able to type anything into the edittext. I have covered all the related answers on this site but none of them worked for me. Maybe I am missing some minor details. It would be helpful if I can get some help.
Code to create edittext dynamically:
EditText editText = new EditText(dt.c);
editText.setBackground(context.getResources().getDrawable(R.drawable.rectangle_answer));
editText.setTextColor(ContextCompat.getColor(dt.c, R.color.md_black_1000));
editText.setTextSize(16);
editText.setTag(questionDetails[0].getOptionId());
editText.setFocusable(true);
editText.setHint(dt.gStr(R.string.enter_your_answer));
editText.requestFocus();
container.Add(editText);
Some of the answers that I covered:
How can I set the focus (and display the keyboard) on my EditText programmatically
Android - EditText made programmatically not showing keyboard
Android: How to open keyboard for editing EditText when click button?
Disable keyboard on EditText
How to disable the keyboard when I click on EditText?
I was having the same problem and nothing worked until I found an answer way down in one of the posts from years ago that worked. I'll repost the weird hack for anyone who might have this problem in the future.
In your xml file, add a dummy edittext to your topmost layout layer that looks like this:
<EditText
android:id="#+id/editTextFix"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:importantForAutofill="no"
tools:targetApi="o"
android:inputType="text"
android:visibility="gone"/>
the dummy edittext will open the keyboard, but your programatically created edittext will still have focus.

Show EditText error when user is not focused on that editText

I have an editText that currently shows an error popover.
editText.setError("You have done something wrong");
Now I need a workflow such that, when user clicks on a button elsewhere, I need to set an error on the editText. But right now, only an error icon is shown.
My question is, is it possible to make it show the whole error text without the user actually clicking (focusing) on it?
Solution 1
Call
editText.requestFocus()
before setting the error.
Solution 2
Use a TextInputLayout.
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.TextInputLayout>
And in code
textInputLayout.setError("Error");
Solution 3
Custom view, up to you.
I use that library MaterialEditText which makes everything more simple... Everything is well explained in the wiki page.
Helper Text and Error Text
helper text:
app:met_helperText="Integer"
error text:
just use original setError(CharSequence error) in java code.
regex check:
validationEditText.isValid("\\d+");
regex validate with error text setting:
validationEditText.validate("\\d+", "Only Integer Valid!");

TextInputEditText not showing drawableRight icon [duplicate]

This question already has answers here:
Unable to use drawable in EditText inside TextInputLayout
(5 answers)
Closed 6 years ago.
I am using code bellow to display User name Input. EditText is working properly but Right side display icon is not visible.
<android.support.design.widget.TextInputLayout
android:id="#+id/login_screen_edit_text_username_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="#+id/login_screen_edit_text_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/label_username"
android:inputType="text"
android:drawableRight="#mipmap/email_icon"
android:text="abcd#gmail.com"
/>
</android.support.design.widget.TextInputLayout>
I am testing this code on Nexus6p android version 6.0. Parent layout is LinearLayout.Please update if anybody facing same issue and got fix for it.
use
android:drawableEnd="#mipmap/email_icon"
instead of
android:drawableRight="#mipmap/email_icon"

Android EditText not Multi Line [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
restrict edittext to single line
I have 2 edit texts. My problem is, when I press the enter button in the keyboard, it creates another set of line. Or it creates like a next line in my edit text. I want to remove it and I want it to be in single line. Even if I enter the enter key in the keyboard, still it won't create a next line.
How do you do it?
Try this in your EditText xml
android:singleLine="true"
<EditText
android:id="#+id/edittextView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:singleLine="true"/>
Try this with your edit text in layout

Android EditText default numeric keyboard and allow text [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
EditText with number keypad by default, but allowing alphabetic characters
Wondering if it is possible to default to a numeric keyboard on focus for an edittext field but also allow users to input characters? None of the input types seem to support this.
Thanks!
I just tried to add a number text field in Android and it ran in the emulator fine. It defaults to bring up the number pad first, but you can switch to characters just as easy. So try to use a number text field.
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number" />

Categories

Resources