Reputation: 958
I have 2 classes, FirstActivity and SecondActivity.
First Activity
Intent intent=new Intent(getApplicationContext(),SecondActivity.class);
startActivity(intent);
Is it possible for SecondActivity to overlay on FirstActivity? ie. FirstActivity gets dimmed, SecondActivity gets displayed on top of FirstActivity.
If it is not possible for 2 different activities, is it possible to do an overlay for 2 views in the same activity? I hope using dialog is not the only option.
Upvotes: 28
Views: 67575
Reputation: 37
1-Take a screenshot of the first activity.
2-(Optional) Darken, tint or blur the screenshot.
3-Then call the second activity and use the first activity screenshot as background for the second activity.
Upvotes: -17
Reputation: 1534
<activity
android:name=".FirstActivity"
android:label="@string/title_activity_first" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:label="@string/title_activity_second"
android:theme="@android:style/Theme.Dialog"
>
<intent-filter>
<action android:name="transparent.text.SECONDACTIVITY"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="192dp"
android:background="#aabbcc"
android:text="Sybrant has provided Takoma with a great team which helped us from the beginning to the final stage of our product, to our fullest satisfaction. We have been able to deliver a high quality of eLearning products to our corporate customers like Nissan with Sybrant’s support”"
tools:context=".FirstActivity" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="43dp"
android:layout_marginLeft="80dp"
android:text="Button" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/button1"
android:layout_below="@+id/textView1"
android:layout_marginRight="42dp"
android:layout_marginTop="80dp"
android:text="TextView" />
</RelativeLayout>
Upvotes: 7
Reputation: 887
If you don't want to do a dialog, you can overlay views using a relative layout.
<?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" >
<LinearLayout android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="some content"
android:textSize="70dp"/>
</LinearLayout>
<LinearLayout android:id="@+id/overlay"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#99000000"
android:clickable="true"
android:visibility="gone">
<EditText android:id="@+id/edittext"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="50dp" />
</LinearLayout>
</RelativeLayout>
The first LinearLayout (id/content) is your base layout where your normal content would go.
The second LinearLayout (id/overlay) is your overlay layout which you'd want to show over top of the base layout. The background color will give give you that faded out background, and you can add whatever you want to that layout to make your overlay. To show the overlay, just change its visibility from gone
to visible
.
Upvotes: 25
Reputation: 6575
I suggest you set your second activity up as a dialog -- which will dim the background. Here is a tutorial that could be helpful:
http://developer.android.com/guide/topics/ui/dialogs.html
http://www.helloandroid.com/tutorials/how-display-custom-dialog-your-android-application
Or you can simply set the theme in the manifest as a dialog for your SecondActivity.
Upvotes: 27