繁体   English   中英

警报对话框文本颜色更改问题

[英]Alert Dialog Text color change issue

我想在我的警报对话框中更改文本颜色。我使用array.xml中的文本。我希望在我的图片中将此橙色形状更改为白色 这是我的array.xml文件代码:-

<resources>
<array name="bug_type">
    <item>
        {"id":\"1\", "type":\"Wrong Question\"}
    </item>
    <item>
        {"id":\"2\", "type":\"Wrong Answer\"}
    </item>
</array>

这是我的活动数据:

AlertDialog.Builder(this, R.style.popuptheme)
            .setTitle("Select bug")
            .setPositiveButton("Ok") { dialog, whichButton ->
                if (bugTypeDialog.selectReportBugType.checkedRadioButtonId > 0) {
                    postBugReport(bugTypeDialog.selectReportBugType.checkedRadioButtonId.toString(), que_id)
                }
                Toast.makeText(this, "Bug Request has been send ..", Toast.LENGTH_LONG).show()
                dialog.dismiss()
            }
            .setNegativeButton("Cancel") { dialog, whichButton ->
                dialog.dismiss()
            }
            .setView(bugTypeDialog)
            .create()
            .show()
}

我想要所有的textview为白色,例如这张照片中的橙色形状 单击此处显示错误图像

您需要为警报对话框创建一个主题。 看一下这个:

http://blog.supenta.com/2014/07/02/how-to-style-alertdialogs-like-a-pro/

在可绘制对象中创建一个textColorSelector

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:color="#0f0"/>
    <item android:state_checked="true" android:color="#fff"/>
    <item android:color="#00f"/>
</selector>

将此选择器应用于RadioButton。

<RadioButton
      ...
      android:textColor="@drawable/textColorSelector"
      />

您有两种方法可以做到这一点

  1. 覆盖默认对话框。 并在对话框上应用主题

     //1. create a dialog object 'dialog' MyCustomDialog builder = new MyCustomDialog(getActivity(), "Exit", errorMessage); AlertDialog dialog = builder.setNegativeButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { ... } }).create(); //2. now setup to change color of the button dialog.setOnShowListener( new OnShowListener() { @Override public void onShow(DialogInterface arg0) { dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(Color.parseColor("#f34235")); } } dialog.show() 

样式文件应类似于:

<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:colorAccent">#0000FF</item>
</style>
  1. 创建自己的自定义对话框

     // create instance of dialog AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); // get inflater and inflate layour for dialogue LayoutInflater inflater = this.getLayoutInflater(); View dialogView = inflater.inflate(R.layout.alert_label_editor, null); // now set layout to dialog dialogBuilder.setView(dialogView); // create instance like this OR directly mentioned in layout Button button= (Button) dialogView.findViewById(R.id.label_field); button.setText("test label"); AlertDialog alertDialog = dialogBuilder.create(); // show dialog alertDialog.show(); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM