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

时间:2016-06-27 09:50:30

标签: android

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

final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this);
bottomSheetDialog.setTitle("title");
//bottomSheetDialog.setContentView(...)
bottomSheetDialog.show();

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

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

1 个答案:

答案 0 :(得分:8)

如果你查看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);

明确指出,底部表格没有标题(有理由)。 (截至支持库版本23.4.0)

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