如何设置输入类型的密码编程EDITTEXT [英] how to set input type as password to edittext programatically
问题描述
大家好,我使用与编辑警报对话框text.So我想设置为密码到编辑文本programatically.I在谷歌已经搜索了很多输入类型,找出这两种方法:
Hi all I am using alert dialog with edit text.So I want to set input type as password to that edit text programatically.I have searched a lot in google and find out these two methods:
final EditText input = new EditText(getActivity());
input.setTransformationMethod(PasswordTransformationMethod.getInstance());
input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
但它不是为我工作,这显示出我想要点text.what的text.But是我不know.So请建议我做taht的问题。
感谢所有提前。
这是对话的code。与编辑文本:
But it is not working for me,It showing the text.But i want dotted text.what is the problem I dont know.So please suggest me to do taht. Thanks to all in advance. this is the code of dialog with edit text:
public void showDialog(){
/* Alert Dialog Code Start*/
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
// alert.setTitle("JPOP"); //Set Alert dialog title here
alert.setMessage(" Please enter password"); //Message here
Log.e("dialog in password ","passworddddddddddddddddd");
// Set an EditText view to get user input
final EditText input = new EditText(getActivity());
// input.setInputType(InputType.TYPE_CLASS_TEXT);
// input.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
// input.setTransformationMethod(PasswordTransformationMethod.getInstance());
// final EditText input = new EditText(getActivity());
input.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
input.setTransformationMethod(new PasswordTransformationMethod());
input.setHint("Password");
input.setSingleLine();
input.setTextSize(14);
alert.setView(input);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
strPassword = input.getEditableText().toString().trim();
if(strPassword.length()!=0){
String prestatus =DataUrls.preferences.getString("Password", "");
if(prestatus.equals(strPassword)){
if(price_reports_check){
price_reports_check=false;
ReportsFragment reportfragment = new ReportsFragment();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.details, reportfragment);
fragmentTransaction.commit();
}else{
PriceListFragment pricelistfragment = new PriceListFragment();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.details, pricelistfragment);
fragmentTransaction.commit();
}
}else
{
showDialog();
Toast.makeText(getActivity(), "The password you entered is wrong", Toast.LENGTH_SHORT).show();
}
}
else
{
showDialog();
Toast.makeText(getActivity(), "Please Enter Password", Toast.LENGTH_SHORT).show();
}
} // End of onClick(DialogInterface dialog, int whichButton)
}); //End of ok....
alert.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
dialog.cancel();
}
}); //End of alert.setNegativeButton
AlertDialog alertDialog = alert.create();
TextView title = new TextView(getActivity());
// You Can Customise your Title here
title.setText("JPOP");
// title.setBackgroundColor(Color.DKGRAY);
title.setPadding(10, 10, 10, 10);
title.setGravity(Gravity.CENTER);
// title.setTextColor(Color.WHITE);
title.setTextSize(20);
alert.setCustomTitle(title);
alert.setCancelable(false);
alert.show();
}
所以,请帮我我做了什么wrong.Thanks @All
So please help me what I did wrong.Thanks @All
推荐答案
您收到此问题的因为你使用 alert.setCustomTitle(职称);
在
input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
input.setTransformationMethod(PasswordTransformationMethod.getInstance());
这使得它的再普通型
要么改变: alert.setCustomTitle(职称);
以 alert.setTitle (在这里你的标题);
或如果您要使用 customeTitle
不是使用以下code
input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
input.setTransformationMethod(PasswordTransformationMethod.getInstance());
alert.setView(input);
在
alert.setCustomTitle(title);
这篇关于如何设置输入类型的密码编程EDITTEXT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!