简体   繁体   English

Android对话框标题和分隔线颜色不变

[英]Android dialog title and divider color not changing

I have created custom Dialog . 我创建了自定义Dialog I wants To change my Dialog title color and Divider line color. 我想更改Dialog标题颜色和分隔线颜色。 I have gone through many answers but still M not successful. 我经历了许多答案,但M仍然没有成功。

I have tried different methods like: 我尝试了不同的方法,例如:

int titleDividerId = resources.getIdentifier("titleDivider", "id", "android");
View titleDivider = dialog.getWindow().getDecorView().findViewById(titleDividerId);
titleDivider.setBackgroundColor(R.color.Red);

And used the following code: 并使用以下代码:

 final Dialog dialog = new Dialog(context);
    dialog.setContentView(R.layout.alertdialog_caseadd);
    dialog.setTitle("Add new court");
    final Resources res = getResources();
    final int titleDividerId = res.getIdentifier("titleDivider", "id", "android");
    inal View titleDivider = dialog.findViewById(titleDividerId);
    titleDivider.setBackgroundColor(res.getColor(android.R.color.holo_orange_dark));
    dialog.getWindow().setBackgroundDrawableResource(R.drawable.alerttitle);
    final EditText casetype= (EditText) dialog.findViewById(R.id.text); 
    Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
    Button dialogButtoncancel = (Button) dialog.findViewById(R.id.dialogButtoncancel);
    dialogButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if(casetype.getText().toString().equals(""))
                Alert.showError("Error", "Please enter case type", CaseType.this);
            else
                 if(Network.isOnline(getApplicationContext()))
                     new WebTask().execute();
                 else
                     Alert.showNetworkError(CaseType.this,inflater);
            dialog.dismiss();
        }
    });

    dialog.show();
    dialogButtoncancel.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            dialog.cancel();

        }
    });

That above code is not working, divider line and title color shows in blue color only. 上面的代码不起作用,分隔线和标题颜色仅以蓝色显示。 Please help me change it. 请帮我改一下。

  final Dialog dialog = new Dialog(context);
    dialog.setContentView(R.layout.alertdialog_caseadd);
    //this method help me for title color change
    dialog.setTitle(Html.fromHtml("<font color='#FFFFFF'>Add new case stage</font>"));
    //this method help me for divider color change
    int dividerId = dialog.getContext().getResources().getIdentifier("android:id/titleDivider", null, null);
    View divider = dialog.findViewById(dividerId);
    divider.setBackgroundColor(getResources().getColor(R.color.white));

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

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