I need to a bottom sheet didn't take all width on the tablet. But it ignore layout_width
attribute in xml. How can I make it?
My bottom sheet class:
public class DetailsFragment extends BottomSheetDialogFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//Create fragment root view
View view = inflater.inflate(R.layout.fragment_details, container, false);
//Set toolbar
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
Drawable icClose = VectorDrawable.getDrawable(getContext(), R.drawable.ic_close_white_24dp);
toolbar.setNavigationIcon(icClose);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
toolbar.inflateMenu(R.menu.details);
RecyclerView rvContent = (RecyclerView) view.findViewById(R.id.rvContent);
FullExpandedListManager lm = new FullExpandedListManager(getContext());
rvContent.setLayoutManager(lm);
rvContent.setHasFixedSize(true);
rvContent.setAdapter(mAdapter);
return view;
}
}
I am not sure if it's the best solution but it works for me at least.
public class DetailsFragment extends BottomSheetDialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new BottomSheetDialog(getContext(), getTheme());
}
public static class BottomSheetDialog extends android.support.design.widget.BottomSheetDialog {
public BottomSheetDialog(@NonNull Context context) {
super(context);
}
protected BottomSheetDialog(@NonNull Context context, final boolean cancelable,
OnCancelListener cancelListener) {
super(context, cancelable, cancelListener);
}
public BottomSheetDialog(@NonNull Context context, @StyleRes final int theme) {
super(context, theme);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setLayout(300 /*our width*/, ViewGroup.LayoutParams.MATCH_PARENT);
}
}
}
P.S. I tried to set a dialog width in the onStart()
method but it doesn't work and I don't know why.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With