Шах*_*Шах 6 android bottom-sheet
我需要一张底纸没有占据平板电脑上的所有宽度。但它忽略layout_width了 xml 中的属性。我怎样才能做到?我的底部工作表类:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
我不确定这是否是最好的解决方案,但至少对我有用。
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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
PS 我试图在onStart()方法中设置一个对话框宽度,但它不起作用,我不知道为什么。
| 归档时间: |
|
| 查看次数: |
4467 次 |
| 最近记录: |