Подтвердить что ты не робот

Наложение активности на другую деятельность или наложение вида на другой

У меня есть 2 класса, FirstActivity и SecondActivity.

Первая активность

Intent intent=new Intent(getApplicationContext(),SecondActivity.class);
startActivity(intent);

Возможно ли, чтобы SecondActivity накладывал на FirstActivity? то есть. FirstActivity становится тусклым, SecondActivity отображается поверх FirstActivity.

Если это невозможно для двух разных действий, возможно ли сделать оверлей для 2 просмотров в одном и том же действии? Я надеюсь, что использование диалога не является единственным вариантом.

4b9b3361

Ответ 1

Я предлагаю вам настроить вторую активность как диалог, который уменьшит фон. Вот учебник, который может быть полезен:

http://developer.android.com/guide/topics/ui/dialogs.html

http://www.helloandroid.com/tutorials/how-display-custom-dialog-your-android-application

Или вы можете просто установить тему в манифесте как диалог для вашего SecondActivity.

Ответ 2

Если вы не хотите делать диалог, вы можете накладывать представления, используя относительный макет.

<?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>

Первый LinearLayout (id/content) - это ваш базовый макет, где будет отображаться ваш обычный контент.

Второй LinearLayout (id/overlay) - это ваш оверлейный макет, который вы хотите показать поверх основного макета. Цвет фона даст вам исчезнувший фон, и вы можете добавить все, что хотите, к макету, чтобы сделать свой оверлей. Чтобы показать наложение, просто измените его видимость от gone до visible.

Ответ 3

В файле манифеста объявить действие secondactivity следующим образом. android: theme = "@android: style/Theme.Dialog". то просто вызовите secondactivity из firstactivity из вашего кода.

 <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>

Вторая активность xml file.you может спроектировать как ваше желание, но для ссылки я опубликовал this.the ключевое понятие в файле манифеста (то есть), как определить вашу secondactivity в манифесте

    <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>

Ответ 4

1-Сделайте снимок экрана первого действия.

2- (Необязательно) Затенение, оттенок или размытие снимка экрана.

3-Затем вызовите второе действие и используйте первый скриншот активности в качестве фона для второго действия.