美文网首页
android window弹出窗

android window弹出窗

作者: 神情自若 | 来源:发表于2018-01-23 11:50 被阅读0次
     Dialog myDialog = new Dialog(MainActivity.this, R.style.Translucent_NoTitle);
            View view = LayoutInflater.from(MainActivity.this).inflate(
                    R.layout.dialog, null);
            myDialog.setContentView(view);
            myDialog.setCanceledOnTouchOutside(true);
            Window dialogWindow = myDialog.getWindow();
            dialogWindow.setGravity(Gravity.CENTER);
            //获取屏幕的宽高
            WindowManager wm = this.getWindowManager();
            int width = wm.getDefaultDisplay().getWidth();
            int height = wm.getDefaultDisplay().getHeight();
            //设置弹出框的大小
            dialogWindow.setLayout(width*5/6,height/3);
            //展示弹出
            myDialog.show();
    
    <!-- 弹窗风格-->
        <style name="Translucent_NoTitle" parent="android:style/Theme.Dialog">
            <item name="android:windowNoTitle">true</item>
            <item name="android:windowBackground">@android:color/transparent</item>
            <item name="android:colorBackgroundCacheHint">@null</item>
            <item name="android:windowIsTranslucent">true</item>
        </style>
    

    相关文章

      网友评论

          本文标题:android window弹出窗

          本文链接:https://www.haomeiwen.com/subject/omcsaxtx.html