我想要一个包含3个视图的对话框1.带有黑色背景的标题2.一些正文文本白色背景3.带有灰色背景的2个按钮的行.
问题是我希望身体的背景颜色为白色,但即使我的视图也将背景颜色设置为白色,在身体的顶部和底部似乎有一些边缘具有不同的背景颜色.
TextView title = new TextView(this);
title.setText("This is my title");
title.setBackgroundColor(Color.BLACK);
title.setPadding(10, 10, 10,10);
title.setGravity(Gravity.CENTER);
title.setTextColor(Color.WHITE);
title.setTextSize(20);
TextView view = new TextView(this);
view.setText("Lorem Ipsum blabla bla \n more bla bla aha hhahah blablalblal.");
view.setBackgroundColor(Color.WHITE);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(false);
builder.setCustomTitle(title);
builder.setView(view);
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Bingo.this.finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
((View)view.getParent()).setBackgroundColor(Color.WHITE); // <-- UGLY fix to avoid stupid margins at top and bottom of the body...
Run Code Online (Sandbox Code Playgroud)
任何想法如何我可以删除代码的最后一行"UGLY修复"?
修复我刚设置的背景颜色问题
builder.setInverseBackgroundForced(true);
Run Code Online (Sandbox Code Playgroud)
所以我的完整代码是
View view = View.inflate(this, R.layout.tos_dialog, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(false);
builder.setIcon(R.drawable.icon);
builder.setTitle("Bla bla title");
builder.setView(view);
builder.setInverseBackgroundForced(true);
builder.setPositiveButton("I agree", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
builder.setNegativeButton("I don't agree", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Bingo.this.finish();
}
});
AlertDialog alert = builder.create();
alert.show();
Run Code Online (Sandbox Code Playgroud)
以及带有自动链接的文本的视图的膨胀xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="10px"
android:textColor="#000"
android:gravity="left"
android:textSize="14px"
android:background="#FFF"
android:autoLink="all"
android:textColorLink="#00F"
android:text="bla bla http://stackoverflow.com is cool, bla bla."
/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8321 次 |
| 最近记录: |