去掉AlertDialog边框的方法

来源:互联网 发布:qt 调用dotnet 编程 编辑:程序博客网 时间:2024/06/05 08:59
          private AlertDialog.Builder mVerBuilder;
private View mViewVer;
mVerBuilder = new AlertDialog.Builder(this, R.style.newPassword);
final AlertDialog alert = mVerBuilder.create();
LayoutInflater layoutInflater = LayoutInflater.from(this);
mViewVer = layoutInflater.inflate(R.layout.systemversion, null);
alert.setView(mViewVer);
alert.show();

WindowManager.LayoutParams lp = alert.getWindow().getAttributes();
lp.width = (int)getResources().getDimension(R.dimen.installation_dialog_width);
lp.dimAmount = ContactsUtil.DIM_AMOUNT_TRANSLUCENT;
alert.getWindow().setAttributes(lp);
alert.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

其中,R.style.newPassword就是去掉边框的关键,它的定义在res/values/style.xml里,内容如下:
<style name="newPassword" parent="@android:Theme.DeviceDefault.Light.Dialog">       
<item name="android:windowIsTranslucent">true</item>        
<item name="android:windowBackground">@android:color/transparent</item>      
<item name="android:windowContentOverlay">@null</item>       
<item name="android:windowNoTitle">true</item>    
</style>
原创粉丝点击