我是android的编程应用程序的新手。对于我的应用程序,我需要 申请开始后的密码请求.....到目前为止一直很好。
但是在调用我的alertdialog方面输入的文本我无法看到txtPIN,因此它总是与背景颜色相同。我正在使用API Lvl 17作为目标API。
如果有人能给我一个提示,我会很高兴。
if (dbManager.getToggle()==true){
final EditText txtPIN = new EditText(this);
txtPIN.setTextColor(color.black);
txtPIN.setInputType(InputType.TYPE_CLASS_NUMBER);
AlertDialog.Builder alert = new AlertDialog.Builder(this,AlertDialog.THEME_HOLO_LIGHT);
alert.setTitle("PIN Security");
alert.setMessage("Please enter PIN");
alert.setView(txtPIN);
alert.setIcon(R.drawable.ic_launcher);
alert.setPositiveButton(getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//comparison of PINs
if (txtPIN.getText().toString().equals(dbManager.getPIN()){
Toast toast = Toast.makeText(getApplicationContext(), R.string.allowed, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 150);
toast.show();
} else {
Toast toast = Toast.makeText(getApplicationContext(), getResources().getString(R.string.denied) + "\n" + txtPIN.getText().toString() + "\n" + dbManager.getPIN(), Toast.LENGTH_SHORT);
toast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 150);
toast.show();
finish();
System.exit(0);
}
}
});
答案 0 :(得分:0)
使用xml创建EditText
,如下所示:
<EditText xmlns:andoird="http://schemas.android.com/apk/res/android"
android:id="@+id/edit_text"
android:inputType="number"
android:textColor="#000000"
android:OTHER_ATTRIBUTES_HERE/>
然后像这样创建AlertDialog
:
AlertDialog.Builder alert = new AlertDialog.Builder(this,AlertDialog.THEME_HOLO_LIGHT);
LayoutInflater inflater = getActivity().getLayoutInflater();
View v = inflater.inflate(R.layout.edit_text_xml_file, null));
alert.setTitle("PIN Security");
alert.setMessage("Please enter PIN");
alert.setView(v);
alert.setIcon(R.drawable.ic_launcher);
EditText txtPIN = (EditText) v.findViewById(R.id.edit_text);
alert.setPositiveButton(getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//comparison of PINs
if (txtPIN.getText().toString().equals(dbManager.getPIN()){
Toast toast = Toast.makeText(getApplicationContext(), R.string.allowed, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 150);
toast.show();
} else {
Toast toast = Toast.makeText(getApplicationContext(), getResources().getString(R.string.denied) + "\n" + txtPIN.getText().toString() + "\n" + dbManager.getPIN(), Toast.LENGTH_SHORT);
toast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 150);
toast.show();
finish();
System.exit(0);
}
}