为什么我在警报对话框下获得此白色背景.我一直试图找出问题一个小时,没有运气.有人可以帮帮我吗?
另外,为什么标题的左侧和右侧有一点暗色调.

protected void onPostExecute(String result) {
//progressDialog.dismiss();
try {
JSONObject json = new JSONObject(result);
String status = json.getString("status");
String message = json.getString("message");
if(status.equals("true")) {
Intent intent = new Intent(context, HomeActivity.class);
intent.putExtra(LoginActivity.EXTRA_MESSAGE, status);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
else{
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setMessage(message)
.setTitle("Error")
.setNeutralButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
}).create().show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
将您的代码更改为 -
Dialog alertDialog = new Dialog(this);
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
alertDialog.setContentView(R.layout.tabs);
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
alertDialog.show();
Run Code Online (Sandbox Code Playgroud)
或者您可以在现有代码中添加主题.
AlertDialog.Builder alertDialog = new AlertDialog.Builder(activity, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
Run Code Online (Sandbox Code Playgroud)
初始化对话框构建器时,将第二个参数作为主题传递.所以改变
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
Run Code Online (Sandbox Code Playgroud)
至
AlertDialog.Builder builder = new AlertDialog.Builder(activity, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
Run Code Online (Sandbox Code Playgroud)
现在是老答案
导入android.support.v7.app.AlertDialog而不是android.app.AlertDialog
在接受的答案中给出.
小智 5
如果您可以访问 Dialog 类,请尝试以下操作:
alertDialog.getWindow().getDecorView().setBackgroundColor(Color.TRANSPARENT);
Run Code Online (Sandbox Code Playgroud)
前:

后:

| 归档时间: |
|
| 查看次数: |
9275 次 |
| 最近记录: |