我的应用程序的主要活动是首选项页面。这是用户单击应用程序图标时显示的内容。我还有一项服务,可以发送用户状态栏通知,并且可以在屏幕上显示半透明覆盖图。我遵循this发布创建我的透明活动,所有这些工作。Android独立透明活动
问题在于,无论何时,我都会显示半透明活动,应用程序的主窗口(首选项页面)在其后面可见。也就是说,半透明覆盖图显示在当前正在运行的任何其他应用程序的顶部。
我该怎么做才能使半透明活动出现时,我的应用程序中没有其他活动可见?
这是我的主要活动在AndroidManifest.xml中定义:
<activity android:name=".AppPreferences" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
我也有半透明的叠加,它使用从Theme.Translucent派生的自定义主题:
<activity android:name=".AppPopupActivity" android:theme="@style/Theme.SemiTransparent">
<intent-filter>
<action android:name="com.app.HIDE_POPUP"></action>
</intent-filter>
</activity>
这里是布局用于半透明覆盖物:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button android:text="@string/button_done"
android:id="@+id/doneButton"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
</RelativeLayout>
</RelativeLayout>
而服务:
<service android:name="AppService">
<intent-filter>
<action android:name="com.app.AppService" />
</intent-filter>
</service>
要显示透明的活动我运行的服务如下:
Intent intent = new Intent(this, AppPopupActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent);
感谢您的帮助
这不就是透明的定义是什么?你可以看到它背后的任何东西。 – nhaarman
我同意尼克,你没有提到你想要发生什么。 – dmon
你们都错了,(我想)这个人有他的活动堆栈的问题,什么摆脱所有的堆栈,并推出他的透明的东西;-) 查看答案。 –