2016-07-16 78 views
0

我用這個進行浮動活動安卓彈出活動展示它MainActivity

public class Conversation extends Activity { 


@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 



    setUpWindow(); 

    setContentView(R.layout.main); 


} 

public void setUpWindow() { 
    // Nothing here because we don't need to set up anything extra for the full app. 
} 
} 

這是簡單的活動,現在我將使它浮在使用本

再拍類

public class PopupConversation extends Conversation { 


@Override 
public void setUpWindow() { 

    // Creates the layout for the window and the look of it 
    requestWindowFeature(Window.FEATURE_ACTION_BAR); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND, 
      WindowManager.LayoutParams.FLAG_DIM_BEHIND); 


    WindowManager.LayoutParams params = getWindow().getAttributes(); 
    params.alpha = 1.0f; // lower than one makes it more transparent 
    params.dimAmount = 0f; // set it higher if you want to dim behind the window 
    getWindow().setAttributes(params); 


    Display display = getWindowManager().getDefaultDisplay(); 
    Point size = new Point(); 
    display.getSize(size); 
    int width = size.x; 
    int height = size.y; 

    if (height > width) { 
     getWindow().setLayout((int) (width * .9), (int) (height * .7)); 
    } else { 
     getWindow().setLayout((int) (width * .7), (int) (height * .8)); 
    } 
} 
} 

現在,當我啓動班級PopupConversation時,它必須顯示我的Conversation活動爲浮動活動,這就是發生

但問題的節目或在我的應用程序啓動MainActivity背後 見照片

它必須是這樣的 ,因爲我們看到它的浮動外應用

enter image description here

現在我的代碼不在應用程序的啓動應用程序之外浮動,並將其浮在應用程序上

enter image description here

正如我們所看到的應用程序啓動並對其

浮動活動開始,這是我在清單

<activity 
     android:name=".activity.PopupConversation" 
     android:theme="@style/Theme.FloatingWindow.Popup" 
     android:configChanges="orientation|screenSize" 
     android:windowSoftInputMode="adjustResize|stateAlwaysHidden" 
     android:clearTaskOnLaunch="true" 
     android:exported="true" 
     tools:ignore="ExportedActivity" 

     > 
    </activity> 

活動,這是我的風格的代碼

<style name="Theme.FloatingWindow.Popup" parent="Theme.AppCompat.NoActionBar" > 
    <item name="android:windowIsFloating">false</item> 
    <item name="android:windowSoftInputMode">stateUnchanged</item> 
    <item name="android:windowContentOverlay">@null</item> 
    <item name="android:windowActionModeOverlay">true</item> 
    <item name="android:windowIsTranslucent">true</item> 
    <item name="android:windowFrame">@null</item> 
    <item name="android:windowAnimationStyle">@style/PopupAnimation</item> 
    <item name="android:windowCloseOnTouchOutside">true</item> 
    <item name="android:backgroundDimEnabled">false</item> 

</style> 

我希望我的活動像第一張照片一樣我想在手機中的任何地方展示它不在應用中

末,我從服務通過調用啓動類此

 Intent window = new Intent(this, PopupConversation.class); 
     window.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     startActivity(window); 
+0

可能是由於to android:clearTaskOnLaunch =「true」 –

+0

@ρяσѕρєяK' true' 是這樣的嗎? – medo

+0

@ρяσѕρєяK我現在嘗試它的第一個啓動應用程序,並顯示它的浮動活動 – medo

回答

0

我利用解決它這個當我啓動它

Intent i = new Intent(); 
i.setClass(this, PopupConversation.class); 
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_MULTIPLE_TASK); 
startActivity(i); 

,所以我只需要添加 Intent.FLAG_ACTIVITY_MULTIPLE_TASK