Android 在AlertDialog中修改编辑文本颜色赢得';行不通

Android 在AlertDialog中修改编辑文本颜色赢得';行不通,android,colors,android-edittext,android-alertdialog,Android,Colors,Android Edittext,Android Alertdialog,我是android编程应用程序的新手。对于我的应用程序,我需要 应用程序启动后的密码请求。。。。。到目前为止还不错 但在调用我的alertdialog时,输入的文本我txtPIN看不见,因此它总是与背景颜色相同。我使用API Lvl 17作为目标API 如果有人能给我一个暗示,我会很高兴的 if (dbManager.getToggle()==true){ final EditText txtPIN = new EditText(this); t

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

            }
        });

使用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.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);
            }

        }

我认为问题在于,
EditText
是用apps
context
创建的,而不是
AlertDialog
的。因此,
EditText
不可能知道主题,因为它无法猜测主题将放置在何处。尝试首先通过调用
AlertDialog=alert.create()
创建一个
AlertDialog
,然后使用
final EditText txtPIN=new EditText(dialog.getContext())创建编辑文本