2016-07-16 73 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