打开具有对话框的活动时应用程序关闭在背景中(样式Theme.Dialog)

问题描述 投票:0回答:2

问题:每当我单击关于按钮时,关于活动在对话框中打开,因为我在AndroidManifest.xml中添加了Theme.Dialog样式,但在后台,应用程序关闭,在对话框的侧面单击后它消失了然后我想要MainActivity(Sudoku)活动)在后台或类似的对话框的背景中保持打开状态。您可以在网页本身轻松解决它:https://github.com/liveHarshit/Sudoku/issues/1并创建拉取请求。

AndroidManifest.xml代码(Sudoku是MainActivity) -

<activity android:name=".About"
            android:label="@string/about_title"
            android:theme="@android:style/Theme.Dialog"
            android:parentActivityName=".Sudoku">
        </activity>

主菜

Button about = (Button)findViewById(R.id.about_button);

        about.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent about_activity = new Intent(Sudoku.this,About.class);
                startActivity(about_activity);
                finish();
            }
        });

布局代码 -

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/about_content"
        android:text="@string/about_text"/>

</ScrollView>

Java类代码 -

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class About extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);
    }

}
android
2个回答
0
投票

你的android:parentActivityName=".Sudoku"是Sudoku,因为你在Manifest.xml中声明了所以停止调用

finish();

让背景继续显示..

Button about = (Button)findViewById(R.id.about_button);

    about.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent about_activity = new Intent(Sudoku.this,About.class);
            startActivity(about_activity);
           // finish(); remove this finish
        }
    });

0
投票

在你MainActivity你将不得不在启动finish()活动后删除About

Button about = (Button)findViewById(R.id.about_button);

    about.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent about_activity = new Intent(Sudoku.this,About.class);
            startActivity(about_activity);
        }
    });
© www.soinside.com 2019 - 2024. All rights reserved.