The default dialog for Android is a black background, white border style, which is pretty good for Android, but it doesn't match your project style, so you have to try to rewrite his style, of course dialog is supported by style rewriting.
Use new Dialog (context, style). Setcontentview (layout);
You can customize the dialog of your project
Of course, the style here plays a vital role, knowing that the white side that doesn't match the project depends on it.
Create a new Style.xml under value
Share My code below:
First: mainactivity
?
12345678910111213141516171819202122232425 |
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super
.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void dialogStyle(View v){
final Dialog d=
new Dialog(
this
, R.style.dialog);
View vv = LayoutInflater.from(
this
).inflate(R.layout.dialog_test,
null
);
TextView delete = (TextView) vv.findViewById(R.id.delete);
d.setCanceledOnTouchOutside(
true
);
d.setContentView(vv);
d.show();
delete.setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
d.dismiss();
}
});
}
}
|
Then: Style
?
123456789 |
<style name=
"dialog" parent=
"@android:style/Theme.Dialog"
>
<item name=
"android:windowFrame"
>
@null
</item>
<item name=
"android:windowIsFloating"
>
true
</item>
<item name=
"android:windowIsTranslucent"
>
false
</item>
<item name=
"android:windowNoTitle"
>
true
</item>
<item name=
"android:background"
>
@null
</item>
<item name=
"android:backgroundDimEnabled"
>
false
</item>
<item name=
"android:windowBackground"
>
@android
:color/transparent </item>
</style>
|
Last XML
?
123456789 |
<!--?xml version=
"1.0" encoding=
"utf-8"
?-->
<linearlayout xmlns:android=
"http://schemas.android.com/apk/res/android" android:layout_width=
"match_parent" android:layout_height=
"match_parent" android:orientation=
"vertical"
>
<relativelayout android:layout_width=
"fill_parent" android:layout_height=
"wrap_content"
>
<textview android:id=
"@+id/delete" android:layout_width=
"238dp" android:layout_height=
"58dp" android:background=
"#2c2c2c" android:text=
"删除联系人" android:textcolor=
"#ffffff" android:gravity=
"center" android:layout_centerhorizontal=
"true"
>
</textview></relativelayout>
</linearlayout>
|
[Android interface] How to get rid of dialog black background and border DEMO