1首先在style文件中:
<style name="BottomSheetDialog" parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">@style/bottomSheetStyleWrapper</item>
</style>
<style name="bottomSheetStyleWrapper" parent="Widget.Design.BottomSheet.Modal">
<item name="behavior_peekHeight">500dp</item>
</style>
2:然后再创建的地方引用这个style创建BottomSheetDialog
public PrinterMenuDialog(@NonNull Context context) {
super(context,R.style.BottomSheetDialog);
initView();
}
这样弹出高度解决了
3:时隔多年回来看这个帖子,看源码得到新的解决思路
布局文件:
<LinearLayout
android:id="@+id/content_layout"
android:layout_width="match_parent"
android:layout_height="@dimen/px_435"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<Button
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="@dimen/px_50"
android:text="确 认 切 换"
android:textColor="@color/white"
android:background="@drawable/seletor_btn"/>
</LinearLayout>
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);
}
}
}