简体   繁体   English

使用 DialogFragment 和导航库时将对话框显示为全屏或对话框

[英]Show dialog as full screen or as dialog when using DialogFragment and Navigation Library

I have a DialogFragment which consists of a search EditText and a RecyclerView.我有一个 DialogFragment,它由一个搜索 EditText 和一个 RecyclerView 组成。 When you click on a search item, dialog is dismissed and selected item is added to another list in the parent fragment.当您单击一个搜索项时,对话框会消失,所选的项会添加到父片段中的另一个列表中。

I use navigation controller to navigate between fragments.我使用导航控制器在片段之间导航。 This DialogFragment is currently defined with fragment tag in navigation graph XML.此 DialogFragment 当前使用导航图 XML 中的fragment标记定义。 I use findNavController().navigate(destinationId) to open it and findNavController().popBackStack() to close it.我使用findNavController().navigate(destinationId)打开它并使用findNavController().popBackStack()关闭它。

I want to show it as dialog in tablets and full screen on mobile devices but failed to do so.我想在平板电脑中将其显示为对话框并在移动设备上全屏显示,但未能这样做。

I tried to create a custom dialog theme whose parent is Theme.MaterialComponents.DayNight.DialogWhenLarge and set it as dialogTheme in the app theme but it overrides attributes in the app theme, like status bar color.我尝试创建一个自定义对话框主题,其父主题是Theme.MaterialComponents.DayNight.DialogWhenLarge并将其设置为应用程序主题中的dialogTheme ,但它会覆盖应用程序主题中的属性,例如状态栏颜色。 I also tried many solutions offered in questions asked here.我还尝试了此处提出的问题中提供的许多解决方案。

How can I achieve this?我怎样才能做到这一点?

When I worked with Diologs set attribute in theme mad them fullscreen当我在主题中使用 Diologs 设置属性时,它们全屏显示

<style name="NotificationDialogTheme" parent="android:Theme.Holo.Dialog">
    <item name="android:windowMinWidthMajor">100%</item>
    <item name="android:windowMinWidthMinor">100%</item>
</style>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM