2014-01-09 98 views
1

为了保持简短,我的目标是弹出活动以显示在当前活动前。如何使活动在当前活动中出现

下面是一个例子http://i.stack.imgur.com/WLUOJ.png

这是一个小部件。当我按下按钮时,此活动会弹出其他活动。

我想要类似的活动弹出。

我是新手。所以,请详细介绍一下。

+0

你刚才创建活动和应用对话的主题。而已。 –

+0

你试过inflater的概念吗? –

+0

将您的活动声明为对话活动。 – AndyN

回答

3

因此,您希望活动的行为类似于对话框弹出窗口。

这可以通过定义一个活动以下的Android清单file--

android:theme="@android:style/Theme.Dialog" 

现在的活动会像一个对话框来实现。

0

使用android:Theme.Holo.Dialog.NoActionBar作为您的活动的主题。或者,您可以创建自定义主题并使用android:Theme.Holo.Dialog.NoActionBar作为其父项。

0

您可以通过创建Activity来实现弹出窗口,只需在清单文件中将该活动声明为对话框即可。

<activity android:name=".MainActivity" 
     android:theme="@android:style/Theme.Dialog"> 

退房Simple Tutorial of Activity as Dialog.

0

是啊,我想尝试一个自定义对话框。这样,您可以将其定制为令人满意的。这里有一个例子:

活动:

LayoutInflater li = LayoutInflater.from(this); 
View promptsView = li.inflate(R.layout.your_xml, null); 
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); 

alertDialogBuilder.setView(promptsView); // set your_xml to alert dialog builder 

    alertDialogBuilder.setCancelable(false).setPositiveButton("OK",new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog,int id) { 
      //action listener for "OK" button 

      } 
      }) 
     .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog,int id) { 
      dialog.cancel(); 

      } 
      }); 

    // create alert dialog 
    AlertDialog alertDialog = alertDialogBuilder.create(); 

    // show it 
    alertDialog.show(); 

}

your_xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

//Custom layout 
</LinearLayout>