问题:每当我单击“关于”按钮时,当我在 AndroidManifest.xml 中添加 Theme.Dialog 样式时,对话框中都会打开“关于活动”,但在后台,应用程序关闭,单击对话框后它消失了,然后我想要 MainActivity(数独活动)在后台或类似的在对话框的后台保持打开状态。您可以在网页本身上轻松解决它:https : //github.com/liveHarshit/Sudoku/issues/1并创建拉取请求。
AndroidManifest.xml 代码(数独是 MainActivity ) -
<activity android:name=".About"
android:label="@string/about_title"
android:theme="@android:style/Theme.Dialog"
android:parentActivityName=".Sudoku">
</activity>
MainActivity数独代码-
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:parentActivityName=".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
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句