View layout = LayoutInflater.from(context).inflate(R.layout.customdialog_cartcount, null);
final Dialog dialog = new Dialog(context);
dialog.setCancelable(true);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.show();
dialog.getWindow().setContentView(layout);
--------------------------------------------------------------
本文实例展示了Android中Dialog去黑边的方法。并且分为保留阴影与不保留阴影两种实现方法。供大家参考借鉴。具体实现方法如下:
1.不保留阴影
代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
|
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
resources
>
<
style
name
=
"dialog"
parent
=
"@android:style/Theme.Dialog"
>
<!--name是我们在使用时要用到的资源的标志,parent是指当前的样式所继承的父类样式-->
<
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"
>@color/clarity</
item
>
<
item
name
=
"android:windowBackground"
>@drawable/clarity</
item
>
<!--这儿也很重要啊,我这儿用了一张透明的.9.png的图,当然用#00000000也是可以的,否则的话这儿出来后有一个黑色的背景-->
<
item
name
=
"android:backgroundDimEnabled"
>false</
item
>
</
style
>
</
resources
>
|
2.保留阴影
代码如下:
1
2
3
4
5
6
7
|
< resources >
< style name = "dialog" parent = "@android:style/Theme.Dialog" >
< item name = "android:windowFrame" >@null</ item >
< item name = "android:windowNoTitle" >true</ item >
< item name = "android:windowBackground" >@null</ item >
</ style >
</ resources >
|
1
2
3
|
final Dialog dialog = new Dialog(context, R.style.dialog);
dialog.setContentView(view);
dialog.show();
|
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<style name="dialog" parent="@android:style/Theme.Dialog"><!--name是我们在使用时要用到的资源的标志,parent是指当前的样式所继承的父类样式-->
<item name="android:windowFrame">@null</item>
<item name="android:windowNoTitle">true</item><!--隐藏标题栏-->
<item name="android:windowBackground">@color/blackalpha</item><!--这儿也很重要啊,我这儿用了一张透明的.9.png的图,当然用#00000000也是可以的,否则的话这儿出来后有一个黑色的背景-->
</style>