即使我设置了标题,Android BottomSheetDialog也无法显示标题

Vee*_*eer 2 android

这是我第一次使用BottomSheetDialog,代码是这样的:

final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this);
bottomSheetDialog.setTitle("title");
//bottomSheetDialog.setContentView(...)
bottomSheetDialog.show();
Run Code Online (Sandbox Code Playgroud)

当我运行此代码时,标题没有显示.

你能解释一下这段代码发生了什么吗?谢谢〜

R. *_*ski 10

如果您查看源代码,android.support.design.widget.BottomSheetDialog您会发现,在它的构造函数中有一行:

// We hide the title bar for any style configuration. Otherwise, there will be a gap
// above the bottom sheet when it is expanded.
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
Run Code Online (Sandbox Code Playgroud)

这清楚地表明,底层表没有标题(有理由).(截至支持库版本23.4.0)

建议:在底部工作表的布局中创建视图的标题.