简体   繁体   English

打开活动,对话框主题“浮动”在当前活动之上

[英]Open activity with Dialog theme “floating” on top of current activity

There may be a better approach for this, and if so please let me know as I am new to android development... 可能有更好的方法,如果是这样,请告诉我,因为我是android开发的新手...

I have an app with a "main" activity. 我有一个带有“主要”活动的应用程序。 From this the user can push a button to open another activity where they can edit settings for the app. 用户可以通过此按钮来打开另一个活动,在此可以编辑应用程序的设置。 Instead of opening the activity on a new 'screen' I would like to open a popup like window (modal) on top of the main activity that will hold the settings activity. 我不想在新的“屏幕”上打开活动,而是要在将保存设置活动的主要活动顶部打开一个类似窗口(模式)的弹出窗口。 The user will be able to see to main screen behind the settings popup but not interact with it until they push 'save' or 'cancel' on settings. 用户将能够看到设置弹出窗口后面的主屏幕,但是直到他们在设置上按“保存”或“取消”时才可以与其交互。

I made my settings activity with the dialog theme. 我使用对话框主题进行设置活动。 When I push the button to open settings, I see the settings activity as I would like, except the main activity goes away and I see my home screen in the background. 当我按下按钮打开设置时,我会看到自己想要的设置活动,除了主要活动消失并且我在后台看到主屏幕。 Then when I push save on settings activity, my main activity comes back full screen. 然后,当我在设置活动中按“保存”时,我的主要活动将返回全屏显示。

Is there an easy way to correct this? 有简单的方法可以纠正此问题吗? Am I not using to correct method to achieve what I am looking to do? 我不是在使用正确的方法来实现自己的目标吗? I've included my onclick handler for the settings button on the main activity. 我在主要活动中为设置按钮添加了onclick处理程序。

    //Settings button
private OnClickListener oclSettingsButtonClick = new OnClickListener() {
    public void onClick(View view) {
        Intent myIntent = new Intent(view.getContext(), settingsActivity.class);
        startActivityForResult(myIntent, 0);
        finish();
    }

Any help is appreciated. 任何帮助表示赞赏。

First, settings are well handled and will probably be easier if you use a preferenceActivity. 首先,可以很好地处理设置,如果使用preferenceActivity,设置可能会更容易。 this out of the box will not get you what you want, but it will result in significantly less coding for you. 开箱即用的解决方案无法满足您的需求,但会大大减少您的编码。 here is a tutorial on that: http://www.kaloer.com/android-preferences you may be able to use a transparent theme on that and get achieve the effect you are looking for, I haven't tried though. 这是一个有关该主题的教程: http : //www.kaloer.com/android-preferences您可能可以在该主题上使用透明主题并获得您想要的效果,但是我没有尝试过。

If you really want a popup overlaying your main activity, a custom dialog will get you there fairly easily. 如果您确实希望弹出窗口覆盖您的主要活动,那么自定义对话框将使您轻松到达那里。

http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog

http://www.helloandroid.com/tutorials/how-display-custom-dialog-your-android-application http://www.helloandroid.com/tutorials/how-display-custom-dialog-your-android-application

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

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