将片段显示为对话框或常规活动

发布于 2024-12-07 16:37:41 字数 88 浏览 5 评论 0原文

在我的应用程序中,我有一个名为“关于”的片段。在手持设备上,我希望这个片段看起来像一个平常的活动,但在平板电脑上,我希望它是一个对话框。处理这种情况首选哪种方式?

In my app I've got a fragment which is called "About". On handhelds I want this fragment to look like a usual activity but on tablets I want it to be a dialog. Which way is preferred to handle this situation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赴月观长安 2024-12-14 16:37:41

styles.xml 中为此创建一个样式(两个 styles.xml 文件,一个位于 values 文件夹中,另一个位于 values-large 中) > 文件夹),但您放入的 value-large 文件夹中的样式继承自 Theme.Dialog。然后让您的片段使用该样式。系统会处理剩下的事情。

或者,使您的类成为 DialogFragment,然后将其嵌入到视图层次结构中,或将其显示为对话框,如下所述:

http://developer.android.com/reference/android/app/DialogFragment.html#DialogOrEmbed

Make a style for this in your styles.xml (two styles.xml files, one in the values folder, the other in a values-large folder) but have the style you put in the values-large folder inherit from Theme.Dialog. Then have your fragment use that style. The system will take care of the rest.

Alternatively, make your class a DialogFragment, and then either embed it into a view hierarchy, or show it as a dialog, as explained here:

http://developer.android.com/reference/android/app/DialogFragment.html#DialogOrEmbed

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文