将片段显示为对话框或常规活动
在我的应用程序中,我有一个名为“关于”的片段。在手持设备上,我希望这个片段看起来像一个平常的活动,但在平板电脑上,我希望它是一个对话框。处理这种情况首选哪种方式?
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
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 thevalues
folder, the other in avalues-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