自定义dialog宽度全屏

AlertDialog.Builder dialog = new AlertDialog.Builder(UnbindBankCardActivity.this, R.style.Dialog_FS);
View view = View.inflate(UnbindBankCardActivity.this, R.layout.view_chakanshilitupian_alertdialog, null);
final AlertDialog alertDialog = dialog.create();
alertDialog.setView(view);
alertDialog.show();

/**
 * 设置dialog宽度全屏
 */
WindowManager m = getWindowManager();
Display d = m.getDefaultDisplay();  //为获取屏幕宽、高
android.view.WindowManager.LayoutParams params = alertDialog.getWindow().getAttributes();  //获取对话框当前的参数值、
params.width = (int) (d.getWidth());    //宽度设置全屏宽度
alertDialog.getWindow().setAttributes(params);     //设置生效

注意!!!!!!!!!!!
以上设置并不能使dialog全屏,还要将dialog的style这样改将原来的  
<style name="Dialog_FS">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowFrame">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:backgroundDimEnabled">true</item>
</style>





阅读更多
个人分类: 自定义view
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭