Android 如何在不删除先前活动的情况下在另一个活动上显示透明活动

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11287525/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 06:44:20  来源:igfitidea点击:

How to display transparent activity on the another activity without removing previous activity

androidandroid-intent

提问by Androjit

How to display transparent activity on the another activity without removing previous activity ?

如何在不删除先前活动的情况下在另一个活动上显示透明活动?

I am able to create transparent activity but when i trying to push it using intent , the previous activity gets removed. I want my transparent activity on the top of previous activity.

我能够创建透明的活动,但是当我尝试使用 intent 推送它时,之前的活动会被删除。我希望我的透明活动位于先前活动的顶部。

Thanks!

谢谢!

回答by Deepak Swami

declare your activity in manifest like this

像这样在清单中声明您的活动

 <activity android:name=".yourActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>

and add a transperent background to your layout like this

并像这样为您的布局添加透明背景

 <?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"
  android:background = "any tranparent image name"  >
 </RelativeLayout>

Edit:

编辑:

i think you are using this to open your transparent activity it finish your previous activity

我认为您正在使用它来打开您的透明活动,它完成了您之前的活动

Intent intent =new Intent(mContext,yourNewActivity.class);
startActivity(intent);
finish();

remove finish from here then your new activity in on top of previous activity like this

从这里删除完成然后你的新活动在以前的活动之上

 Intent intent =new Intent(mContext,yourNewActivity.class);
 startActivity(intent);

Hope help..

希望帮助..

回答by Nanda Gopal

For the AppCompatstyle, you can use the following code in your styles.xml, and the add that in your manifest.

对于AppCompat样式,您可以在您的 中使用以下代码styles.xml,并在您的manifest.

styles.xml

样式文件

<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowIsTranslucent">true</item>   
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>   
    <item name="android:windowNoTitle">true</item>
    <item name="android:backgroundDimEnabled">true</item>
    <item name="colorPrimaryDark">@android:color/transparent</item>
</style>

Manifest

显现

<activity android:name=".HomeActivity"
android:theme="@style/Theme.Transparent" />

回答by 0gravity

I don't know why would you want that, but maybe a Custom dialogcan do what you are looking for.

我不知道你为什么想要那个,但也许自定义对话框可以做你正在寻找的东西。

EDIT: This question has been answered before: How do I create a transparent Activity on Android?

编辑:这个问题之前已经回答过:How do I create a transparent Activity on Android?

I don't want to be rude, but I think you should do more research from your part. Also, can you post some code to see what exactly are you trying out, it also shows that you are trying something.

我不想粗鲁,但我认为你应该从你的角度做更多的研究。另外,您能否发布一些代码以查看您到底在尝试什么,这也表明您正在尝试某些东西。