Programmatically change input type of the EditText from PASSWORD to NORMAL & vice versa
Add an extra attribute to that EditText
programmatically and you are done:
password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
For numeric password (pin):
password.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
Also, make sure that the cursor is at the end of the text in the EditText
because when you change the input type the cursor will be automatically set to the starting point. So I suggest using the following code:
et_password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
et_password.setSelection(et_password.getText().length());
When using Data Binding, you can make use of the following code:
<data>
<import type="android.text.InputType"/>
.
.
.
<EditText
android:inputType='@{someViewModel.isMasked ?
(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD) :
InputType.TYPE_CLASS_TEXT }'
If using Kotlin:
password.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
Set inputType for an EditText Programmatically?
According to the TextView docs, the programmatic version of android:password is setTransformationMethod(), not setInputType(). So something like:
mEdit.setTransformationMethod(PasswordTransformationMethod.getInstance());
should do the trick.
Programmatically created EditText's Input Type Password not working
Just replace edittext.setSingleLine(true);
with edittext.setMaxLines(1);
AlertDialog.Builder alert = new AlertDialog.Builder(this);
final EditText edittext = new EditText(ChildMainScreen.this);
edittext.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
edittext.setMaxLines(1);
alert.setMessage("Please enter password to continue");
alert.setView(edittext);
alert.show();
Change EditText value from text to password and vice versa on ToggleButton checked
Here is the working code:
toggleCommand.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
if (toggleCommand.isChecked())
{
input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
}
else
{
input.setInputType(InputType.TYPE_CLASS_TEXT);
}
}
});
More info: http://thenewboston.org/watch.php?cat=6&number=27
Programmatically change input type of the EditText from PASSWORD to NORMAL & vice versa
edit: Further explanation on setInputType here: http://developer.android.com/reference/android/text/InputType.html
How to change EditText input type from password to visible?
try it this code
checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked) {
password.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
} else {
password.setInputType(129);
}
}
});
How to make android edittext action like password input when login wi-fi on android?
You should use this method to do so setTransformationMethod()
, i.e.
inputPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
inputPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
you can get more details here
Related Topics
How to Add New Column to Android SQLite Database
Error: Resource Android:Attr/Fontvariationsettings Not Found
Android Speech Recognition Continuous Service
Error Message:This Android Sdk Requires Android Developer Toolkit Version 22.6.1 or Above
Android Studio - How to Make an Avd with Arm Instead of Haxm
How to Set Up Dagger Dependency Injection from Scratch in Android Project
How to Check Edittext's Text Is Email Address or Not
How to Get Response as String Using Retrofit Without Using Gson or Any Other Library in Android
Android - Keep Listview's Item Highlighted Once One Has Been Clicked
How to Attach the Android Support Library Source in Eclipse
Getapplicationcontext(), Getbasecontext(), Getapplication(), Getparent()
Why Do I Get Com.Google.Android.Gms.Common.Api.Apiexception: 10:
Pathpattern to Match File Extension Does Not Work If a Period Exists Elsewhere in the File Name
Manifest Merger Failed Targeting Android 12
Progressdialog Not Shown When Asynctask.Get() Called