Android 使对话框全屏显示 [英] Android make a dialog appear in fullscreen

查看:37
本文介绍了Android 使对话框全屏显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了顶部和底部的一些空间外,我需要对话框来填充屏幕.我一直在寻找解决方案,但找不到,可能是因为我在 onClickListener 中声明了它.有人能给出解决方案吗?

I need the dialog to fill the screen except for some space at the top and the bottom. I've search for a solution but couldn't find one probably because I'm declaring it in an onClickListener. Can someone please give a solution?

活动代码:

sort.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                AlertDialog.Builder sort = new AlertDialog.Builder(HomeScreen.this);
                // Get the layout inflater
                LayoutInflater inflater = HomeScreen.this.getLayoutInflater();
                View sortView = inflater.inflate(R.layout.sort_layout, null);
                sort.setView(sortView);
                sort.create().show();
            }
        });

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginBottom="50dp"
    android:layout_marginTop="50dp"
    android:background="@color/white"
    android:orientation="vertical" android:layout_gravity="center">
    + some more stuff here I dont think it's relevant
</LinearLayout>

推荐答案

这里设置你的屏幕宽度和对话框的宽度

here set your screen width and width to the dialog

WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = width;
    lp.height = height;
    dialog.getWindow().setAttributes(lp);

或者在您的样式中创建这样的样式

or in your styles create a style like this then

 <style name="DialogTheme" parent="android:Theme.Dialog">

    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">fill_parent</item>


    <!-- No backgrounds, titles or window float -->
    <item name="android:windowBackground">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">false</item>
</style>

像这样创建一个对话框对象

create a dialog object like this

dialog = new Dialog(this, R.style.DialogTheme);

:

为将填充的任何设备获取这样的宽度和高度..

get width and height like this for any device it will fills..

WindowManager manager = (WindowManager) getSystemService(Activity.WINDOW_SERVICE);
    int width, height;
    LayoutParams params;

    if (Build.VERSION.SDK_INT > VERSION_CODES.FROYO) {
        width = manager.getDefaultDisplay().getWidth();
        height = manager.getDefaultDisplay().getHeight();
    } else {
        Point point = new Point();
        manager.getDefaultDisplay().getSize(point);
        width = point.x;
        height = point.y;
    }

这篇关于Android 使对话框全屏显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆