how to remove ` frequently used email ` toast on my edit text? - android

as you can see from the image above, there is something like a toast with text "Frequently used email" . whenever I complete typing an email then that toast will appear, I don't think I make it programmatically. It seems it appears only on Android 10, in my Android Lollipop that toast doesn't appear. I use Xiaomi Redmi Note 7 for my Android 10.
I want to remove that toast from my edittext. how to do that ?
here is the XML for the edittext
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/email_login_textInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="16dp"
android:theme="#style/TextInputLayoutAppearance"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView_back_button">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/email_textView_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="#string/email"
android:inputType="textEmailAddress" />
</com.google.android.material.textfield.TextInputLayout>
and in Kotlin code, I just have this listener
emailTextView.setOnFocusChangeListener { v, hasFocus ->
val emailText = emailTextView.text.toString()
if (!emailText.isEmpty()) {
if (!hasFocus && (!emailText.contains("#") || (!emailText.contains(".")))) {
emailTextInputLayout.isErrorEnabled = true
emailTextInputLayout.error = "wrong email format"
} else if (!hasFocus) {
emailTextInputLayout.isErrorEnabled = false
emailTextInputLayout.error = ""
}
}
}
I have tried to change/remove android:inputType="textEmailAddress" , but that toast is still appear

I was also facing this problem and have solved by adding the following -
android:inputType="textNoSuggestions|textEmailAddress"
textNoSuggestions will prevent the 'frequently used email' toast and since the EditText is for email address so you need to add textEmailAddress as well

Related

For setting limit in multiline edittext 's each line

I want to set limits in edittext each line and then click enter key cursor move to the next line in android studio, please answer how can I do this..my codes are
<EditText
android:inputType="textMultiLine|number"
android:singleLine="false"
android:digits= "0,1,2,3,4,5,6,7,8,9"
android:id="#+id/number"
android:hint="Enter Number Here..."
android:paddingLeft="10dp"
android:textSize="15sp"
android:fontFamily="sans-serif"
android:layout_margin="5dp"
android:gravity="top|left"
android:background="#ffffff"
android:layout_width="match_parent"
android:layout_height="130dp" />
when I click enter key it did not work and when I remove inputType from XML code enter key works please solve
Follow steps below:
Step 1: add these lines in your XML
android:maxLines="1"
android:imeOptions="actionNext"
Step 2(optional): use following code in your Activity
If you want to do some action when user clicks next
editText.setOnEditorActionListener((v, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_NEXT) {
//your code here
return true;
}
return false;
});
I m using AndroidX with Java 1_8 enabled
Hope this will help!
May be you need to use android:minEms or android:maxEms. Read more in following link:
https://developer.android.com/reference/android/widget/EditText

How do I handle editText Send event in Kotlin?

I am new to Kotlin and I'm stuck at a specific point.
I have this EditText in one of my UI Fragments:
<EditText
android:id="#+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="100dp"
android:ems="10"
android:gravity="start|top"
android:imeOptions="actionSend"
android:inputType="text" />
How do I now call a function by clicking on the send button on the keyboard.
And could anyone please let me know where do I've to put that code.
Thank you very much!
This way to write in kotlin
editText3.setOnEditorActionListener { textView , actionId, event ->
if(actionId == EditorInfo.IME_ACTION_SEND){
//doSomething()
true
} else {
false
}
}

EditText keeps writing in single line Android

I know this question has been asked before and I tried several answers but none of them worked. I have an EditText where the user gives caption of a picture. The editText keeps writing the text in a single line. It doesn't go to the next line. I want the text to go to next line automatically when it reaches the screen's border/end. Here's my code. Please let me know if I have made any mistakes in my code.
<EditText
android:layout_marginTop="8dp"
android:layout_width="match_parent"
android:layout_height="80dp"
android:gravity="start"
android:inputType="textMultiLine|textPersonName"
android:hint="Write some thing about the photo"
android:maxLength="160"
android:paddingLeft="8dp"
android:textSize="14sp"
android:layout_below="#+id/privacyHolder"
android:lines="3"
android:layout_alignParentEnd="true"
android:ems="20"
android:paddingEnd="4dp"
android:maxLines="3"
android:layout_marginEnd="4dp"
android:layout_marginStart="4dp"
android:paddingTop="4dp"
android:background="#drawable/roundedbutton"
android:id="#+id/description"
/>
In the Resource, design your edit text as follow:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text|textMultiLine|textCapSentences"
android:gravity="left"
/>
In the activity you can use TextWatcher to listen when text exceeds few character and automatically move down.
Here is the snippet :
private boolean isReach = false;
// put this in onCreate method
edittext.addTextChangedListener(new TextWatcher(){
#Override
public void afterTextChanged(Editable s) {
// if edittext has 20 character reached add a new line, you can use either 20 or more here
if(yourtextEd.getText().length() == 20 && !isReach) {
yourtextEd.append("\n");
isReach = true;
}
// if edittext has less than 20 characters and isReach has set , change
if(yourtextEd.getText().length() < 20 && isReach) isReach = false;
}
});
Hope this will help you.

Display Error message at the Right End margin in editText as show in Screenshot below

I want to display the error message as shown in the screenshot.Whenever there is en error I want to display error message and if everything thing correct then not to display the error message.I don't want pop up . Eg. editText.setError();
You can use this
String errorMsg = "invalid email";
EditText editText = (EditText) findViewById(R.id.editText);
editText.setError(errorMsg);
Hope this will hepl you.
You could use the new support library features http://www.google.com/design/spec/components/text-fields.html#
If you are using studio add this compile 'com.android.support:design:22.2.0'
<android.support.design.widget.TextInputLayout
android:id="#+id/fNameLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp">
<EditText
android:id="#+id/fName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="First Name"/>
</android.support.design.widget.TextInputLayout>

Design Android EditText to show error message as described by google

I need an EditText that looks like this onError:
calling onError looks like this instead :
Note: the app is running on SDK 19 (4.4.2)
min SDK is 1
Is there a method similar to setError that does this automatically,
or do I have to write the code for it ?
Thank you
There's no need to use a third-party library since Google introduced the TextInputLayout as part of the design-support-library.
Following a basic example:
Layout
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="true">
<android.support.design.widget.TextInputEditText
android:id="#+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your name" />
</android.support.design.widget.TextInputLayout>
Note: By setting app:errorEnabled="true" as an attribute of the TextInputLayout it won't change it's size once an error is displayed - so it basically blocks the space.
Code
In order to show the Error below the EditText you simply need to call #setError on the TextInputLayout (NOT on the child EditText):
TextInputLayout til = (TextInputLayout) findViewById(R.id.text_input_layout);
til.setError("You need to enter a name");
Result
To hide the error and reset the tint simply call til.setError(null).
Note
In order to use the TextInputLayout you have to add the following to your build.gradle dependencies:
dependencies {
compile 'com.android.support:design:25.1.0'
}
Setting a custom color
By default the line of the EditText will be red. If you need to display a different color you can use the following code as soon as you call setError.
editText.getBackground().setColorFilter(getResources().getColor(R.color.red_500_primary), PorterDuff.Mode.SRC_ATOP);
To clear it simply call the clearColorFilter function, like this:
editText.getBackground().clearColorFilter();
Call myTextInputLayout.setError() instead of myEditText.setError().
These container and containment have double functionality on setting errors. Functionality you need is container's one. But you could require minimal version of 23 for that.
Your EditText should be wrapped in a TextInputLayout
<android.support.design.widget.TextInputLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tilEmail">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/etEmail"
android:hint="Email"
android:layout_marginTop="10dp"
/>
</android.support.design.widget.TextInputLayout>
To get an error message like you wanted, set error to TextInputLayout
TextInputLayout tilEmail = (TextInputLayout) findViewById(R.id.tilEmail);
if (error){
tilEmail.setError("Invalid email id");
}
You should add design support library dependency. Add this line in your gradle dependencies
compile 'com.android.support:design:22.2.0'
reVerse's answer is great but it didn't point out how to remove the floating error tooltip kind of thing
You'll need edittext.setError(null) to remove that.
Also, as someone pointed out, you don't need TextInputLayout.setErrorEnabled(true)
Layout
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter something" />
</android.support.design.widget.TextInputLayout>
Code
TextInputLayout til = (TextInputLayout) editText.getParent();
til.setError("Your input is not valid...");
editText.setError(null);
If anybody still facing the error with using google's design library as mentioned in the answer then, please use this as commented by #h_k which is -
Instead of calling setError on TextInputLayout, You might be using setError on EditText itself.
TextInputLayout til = (TextInputLayout)editText.getParent();
til.setErrorEnabled(true);
til.setError("some error..");
private EditText edt_firstName;
private String firstName;
edt_firstName = findViewById(R.id.edt_firstName);
private void validateData() {
firstName = edt_firstName.getText().toString().trim();
if (!firstName.isEmpty(){
//here api call for ....
}else{
if (firstName.isEmpty()) {
edt_firstName.setError("Please Enter First Name");
edt_firstName.requestFocus();
}
}
}

Categories

Resources