显示新活动上previous活动之上previous

2023-09-12 04:40:31 作者:恋上你的温柔

我有活性的具有向下按钮(见上图)。当我preSS这个按钮,我想发起一个活动B上的活动A的顶部,这样一些活动A的底部仍清晰可见。 b活动又可以开展一些其他活动(C,D等),但这样的,他们只显示相同的屏幕区域内B.任何人都知道这是可能的,我怎么能走呢?

  

修改:我知道我可以添加安卓主题=@安卓风格/ Theme.Dialog来我的活动清单但据我所知,这将显示在屏幕的中心,而不是这样的,我可以调整它,我怎么样。纠正我,如果我错了......

解决方案

这是XML的应该是在活动前的活动

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:后台=#00000000>
     <的LinearLayout
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =0
        机器人:layout_weight =0.6
        机器人:后台=#000000>
     //使用这个为新的活动内容
     < / LinearLayout中>
     <的LinearLayout
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =0
        机器人:layout_weight =0.4
        机器人:后台=#00000000>
     //这是空的
     < / LinearLayout中>
< / LinearLayout中>
 

现在在清单作为活动的B,C,...等等:

 <活动
        机器人:标签=@字符串/ APP_NAME
        机器人:名称=。ActivityB
        机器人:主题=@风格/ Theme.Transparent
        机器人:screenOrientation =画像>
 
学历内卷时代,宇宙的尽头是什么 复旦职业大神说

在值/ styles.xml

 < XML版本=1.0编码=UTF-8&GT?;
<资源>
    <样式名称=Theme.Transparent父=机器人:Theme.NoTitleBar>
        <项目名称=机器人:windowIsTranslucent>真< /项目>
        <项目名称=机器人:windowBackground> @可绘制/ theme_transparent< /项目>
    < /风格>
< /资源>
 

最后,在绘制/ theme_transparent.xml

 < XML版本=1.0编码=UTF-8&GT?;
<形状的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    [固体机器人:颜色=#00000000>< /固>
< /形状>
 

I have an Activity A which has a "down" button (see image above). When I press this button I want to launch an Activity B on top of Activity A so some of Activity A at the bottom is still visible. Activity B can in turn launch a number of other Activities (C, D etc) but such that they only display within the same screen area as B. Anyone know if this is possible and how I could go about it?

Edit: I am aware that I can add android:theme="@android:style/Theme.Dialog" to my Activity manifest but as far as I am aware this displays in the centre of the screen and not such that I can resize it how I like. Correct me if I am wrong...

解决方案

This is the xml for activities that should be on top of activity a

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#00000000" >
     <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0"
        android:layout_weight="0.6"
        android:background="#000000" >
     //use this for your new activity contents
     </LinearLayout>
     <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0"
        android:layout_weight="0.4"
        android:background="#00000000" >
     //this is empty
     </LinearLayout>
</LinearLayout>

Now in your manifest for activity B,C ,... etc:

    <activity
        android:label="@string/app_name"
        android:name=".ActivityB"
        android:theme="@style/Theme.Transparent"
        android:screenOrientation="portrait" >

in values/styles.xml :

<?xml version="1.0" encoding="utf-8"?>  
<resources>
    <style name="Theme.Transparent" parent="android:Theme.NoTitleBar">  
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@drawable/theme_transparent</item>
    </style>
</resources>  

Finally in drawable/theme_transparent.xml :

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#00000000" ></solid>
</shape>

 
精彩推荐