0

我是android编程应用程序的新手。对于我的应用程序,我需要在应用程序启动后请求密码.....到目前为止一切顺利。

但是在调用我的 alertdialog 时,输入的文本 i 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);
                }

            }
        });
4

1 回答 1

0

像这样创建您的EditText使用 xml:

<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);
            }

        }
于 2013-05-06T19:26:00.737 回答