BottomSheetDialog高度不足够显示全部内容的解决办法

  1首先在style文件中:

 



 

2:然后再创建的地方引用这个style创建BottomSheetDialog 

 

 

public PrinterMenuDialog(@NonNull Context context) {
    super(context,R.style.BottomSheetDialog);
    initView();
}

这样弹出高度解决了

3:时隔多年回来看这个帖子,看源码得到新的解决思路

布局文件:



    

    

 

java 文件:

package com.hytch.fthire.widgets;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.BottomSheetDialog;
import android.view.View;
import android.widget.FrameLayout;

import com.hytch.fthire.R;

/**
 * author : xubaipei
 * create date: 2019-05-22
 */
public class BottomDialog extends BottomSheetDialog {
    int peekHeight = 0;

    public BottomDialog(@NonNull Context context) {
        super(context);
    }

    public BottomDialog(@NonNull Context context, int theme) {
        super(context, theme);
    }

    public BottomDialog(@NonNull Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onStart() {
        super.onStart();

    }

    @Override
    public void show() {
        super.show();
        if (peekHeight == 0){
            View container = findViewById(R.id.content_layout);
            container.measure(0,0);
            peekHeight = container.getMeasuredHeight();

            FrameLayout bottomSheet = (FrameLayout)findViewById(android.support.design.R.id.design_bottom_sheet);
            BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
            behavior.setPeekHeight(peekHeight);
        }
    }
}

 

你可能感兴趣的:(android-开发)