DialogFragment全屏加控件显示在底部

大家都知道dialogfragment单纯的全屏显示很容易(什么什么Match_parent解决),单纯的显示在底部也很容易(什么什么Gravity.Bottom解决),但是又要全屏又要显示在底部就不容易了。

为什么呢?全屏显示,把几个控件显示在底部,你会发现这个控件神奇的消失了。


就像这样,上半部分是0dp,weight=1,到了手机上,下面这些控件不会显示,除非你上半部分的0dp改成固定的长度。

就算你使用这样的代码

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/pop_content"
    android:background="@color/colorPrimary">
    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@mipmap/pop_close"
        android:layout_gravity="center_horizontal|bottom"/>
</FrameLayout>

他会全屏变成colorprimary的颜色,并不会显示imageview。

1.使用这样的方法

WindowManager.LayoutParams attributes = window.getAttributes();
attributes.width=WindowManager.LayoutParams.MATCH_PARENT;
attributes.height=WindowManager.LayoutParams.MATCH_PARENT-getBarHeight();
他会全屏显示,但是imageview不显示


2.使用这样的方法

这种方法,他会显示imageview,但是通知栏被遮住了,我想通知栏不被遮住.因为我原本界面是显示通知栏的,弹出dialog后整个界面往上滑动.这样的效果不好.

this.setStyle(DialogFragment.STYLE_NORMAL,android.R.style.Theme_NoTitleBar_Fullscreen);

                WindowManager.LayoutParams attributes = window.getAttributes();
                attributes.width=WindowManager.LayoutParams.MATCH_PARENT;
//                attributes.height=WindowManager.LayoutParams.MATCH_PARENT-getBarHeight();


总结下来就是:1要全屏显示,2通知栏不被顶掉;

那我就自定义一个样式

<style name="ShowTitleDontShowActionBar">
    <item name="android:windowNoTitle">false</item>
    <item name="android:layout_height">match_parent</item>
    <item name="android:fitsSystemWindows">true</item>
    <item name="android:windowActionBar">false</item>
</style>

this.setStyle(DialogFragment.STYLE_NORMAL,R.style.ShowTitleDontShowActionBar);
        Dialog dialog = getDialog();
        if(dialog!=null){
            Window window = dialog.getWindow();
            if(window!=null){
                WindowManager.LayoutParams attributes = window.getAttributes();
                attributes.width=WindowManager.LayoutParams.MATCH_PARENT;
//                attributes.height=WindowManager.LayoutParams.MATCH_PARENT-getBarHeight();
//                attributes.gravity= Gravity.BOTTOM;
                window.setAttributes(attributes);
//                window.setBackgroundDrawable(null);
                window.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(getContext(),R.color.half_translucent)));
            }
        }

要显示title(就是通知栏),要全屏height=match_parent.好了下面两行代码不知道有没有用,加上再说。完全O鸡巴K,问题解决
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值