我创建了自定义Dialog
。
我想更改我的Dialog
标题颜色和分隔线颜色。
我已经经历了很多答案,但仍然没有成功。
我尝试过不同的方法,如:
int titleDividerId = resources.getIdentifier("titleDivider", "id", "android");
View titleDivider = dialog.getWindow().getDecorView().findViewById(titleDividerId);
titleDivider.setBackgroundColor(R.color.Red);
并使用以下代码:
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();
}
});
上面的代码不起作用,分隔线和标题颜色仅显示为蓝色。 请帮我改一下。
答案 0 :(得分:0)
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));