2014-01-09 100 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>