如何在Android中将对话框显示为我的活动? [英] How can I show my activity as a dialog in Android?

查看:236
本文介绍了如何在Android中将对话框显示为我的活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发第一个Android应用程序,并尝试为我的活动设置风格。最终,我希望我的活动与对话框一样。我已经在我的 AndroidManifest.xml 中使用以下代码给我所有的活动 Theme.Dialog 风格:

 < application 
android:icon =@ drawable / group
android:label =@ string / app_name
android:theme =@ android:style / Theme.Dialog>
< / application>

这给我的活动漂浮外观和对话框的边框,但不是样式的标题。标题与普通对话框背景颜色和外观相同,而不是实际对话框中的标题背景和边框。请注意,在两个示例中,标题在其下有一个很好的边框,而在第二个示例中,它具有渐变背景。



有没有办法确保我的活动中的标题以某种方式继承系统对话框标题,以便有效地复制我的活动对话框的外观 - 除了边框和float,它附带了 Theme.Dialog style?



请注意,我不想将我的活动称为另一个对话框,我只是希望它像一个dilaog ,即使它是按照我的清单的意图过滤器响应意图加载的。






$ b $在 onCreate()中调用某些方法,可能有一些方法可以让我的活动把自己变成一个实际的对话?请记住,活动仍然需要能够对系统的意图做出回应。

解决方案

决定查看 我放弃了我的问题寻找方法想法而不是实现想法此处。 GalDude33帮我弄清楚如何实现我想要的。他的回答是这个问题的答案。


I am working on my first Android application, and am trying to style my activity. Ultimately, I would like for my activity to look the same as a dialog. I have given all my activities the Theme.Dialog style using the following code in my AndroidManifest.xml:

<application
    android:icon="@drawable/group"
    android:label="@string/app_name" 
    android:theme="@android:style/Theme.Dialog">
</application>

This gives my activities the "floating" appearance and the borders of a dialog, but not the styled title. The title just has the same color and appearance as the general dialog background, not the "header" background and border as in a "real" dialog. Notice how in both examples the header has a nice border under it and in the second one, it has a gradient background.

Is there a way to make sure the title on my activity somehow inherits the system dialog title so as to effectively replicate the look of a dialog for my activity - in addition to the border and "float" which comes with the Theme.Dialog style?

Note that I do not want to call my activity as a dialog from another, I just want it to LOOK like a dilaog, even when it is loaded in response to an intent as per my manifest's intent-filters.

ADD: Is there perhaps some way I can have my activity, when it spins up in onCreate(), call some method to turn itself into an actual dialog? Keep in mind the activity still needs to be able to respond to intents from the system.

解决方案

After deciding to look at what I wanted to do, instead of how to do it specifically, I found a different approach. I reasked my question looking for approach ideas instead of implementation ideas here. GalDude33 helped me figure out how to achieve what I wanted. His answer there was the answer to this Q.

这篇关于如何在Android中将对话框显示为我的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆