我有使用AlertDialog.Builder构建的以下AlertDialog,这是我使用的代码:
ContextThemeWrapper ctw = new ContextThemeWrapper(activity, R.style.MyTheme );
AlertDialog.Builder builder = new AlertDialog.Builder(ctw);
builder.setAdapter(adapter, null);
builder.setNegativeButton(R.string.ok_btn,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
int selectRemoveButtonId = R.string.remove_all;
for (int i = 0; i < selected.length; i++) {
if (selected[i] == false) {
selectRemoveButtonId = R.string.select_all;
}
}
builder.setNeutralButton(selectRemoveButtonId,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.setOnCancelListener(this);
final AlertDialog dialog = builder.create();
dialog.getListView().setOnItemClickListener(this);
dialog.getListView().setDivider(new ColorDrawable(getResources().getColor(R.color.Light_Black)));
dialog.getListView().setDividerHeight(1);
dialog.show();
dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setBackgroundDrawable(getResources().getDrawable(R.drawable.messege_bg_selector));
dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setHeight(100);
changeAllSelection = dialog.getButton(DialogInterface.BUTTON_NEUTRAL);
changeAllSelection.setHeight(100);
changeAllSelection.setBackgroundDrawable(getResources().getDrawable(R.drawable.messege_bg_selector));
changeAllSelection.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (((Button) v).getText().equals(getContext().getString(R.string.select_all)))
{
ListView list = ((AlertDialog) dialog).getListView();
for (int i = 0; i < list.getCount(); i++)
{
selected[i] = true;
list.setItemChecked(i, true);
}
adapter.notifyDataSetChanged();
((Button) v).setText(R.string.remove_all);
}
else
{
ListView list = ((AlertDialog) dialog).getListView();
for (int i = 0; i < list.getCount(); i++)
{
selected[i] = false;
list.setItemChecked(i, false);
}
adapter.notifyDataSetChanged();
((Button) v).setText(R.string.select_all);
}
}
});
结果如下:
现在我想更改所选部分:
1。我想删除白色边框。
2. 我要将按钮部分的灰色更改为黑色。
有人知道如何做到这一点吗?
感谢。
答案 0 :(得分:0)
要从AlertDialog中删除边框,请尝试以下操作:
AlertDialog.Builder oAlertDialog = new AlertDialog.Builder(mContext);
oAlertDialog.setInverseBackgroundForced(true);