gpt4 book ai didi

android - fragment 对话框使应用程序崩溃,还有其他解决方法吗?

转载 作者:搜寻专家 更新时间:2023-11-01 08:43:51 25 4
gpt4 key购买 nike

试图移除 Android 应用的顶部横幅层,我在 Android Manifest 文件中做了这个更改,

android:theme="@android:style/Theme.NoTitleBar"

这使应用程序崩溃了,我根据 Stackoverflow 本身的另一个问题进行了更改

public class MainActivity extends AppCompatActivity

public class MainActivity extends FragmentActivity

它起作用了,但是,在同一个 Activity 中还有一个对话框,每当单击该对话框时,它都会再次使应用程序崩溃,因此正在寻找修复方法!任何帮助将不胜感激。

这是日志:

05-16 21:25:27.796    1839-1839/zyia.alarm.zyia.zyia E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: zyia.alarm.zyia.zyia, PID: 1839
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:113)
at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
at android.support.v7.app.AppCompatDialog.<init>(AppCompatDialog.java:47)
at android.support.v7.app.AlertDialog.<init>(AlertDialog.java:92)
at android.support.v7.app.AlertDialog$Builder.create(AlertDialog.java:882)
at zyia.alarm.zyia.zyia.FireMissiles.onCreateDialog(FireMissiles.java:26)
at android.support.v4.app.DialogFragment.getLayoutInflater(DialogFragment.java:308)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:458)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

对话框 Activity 的代码:

import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;

public class FireMissiles extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

LayoutInflater inflater = getActivity().getLayoutInflater();

builder.setView(inflater.inflate(R.layout.main_info, null))
.setPositiveButton(R.string.fire, new

DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// FIRE ZE MISSILES!
}
});

// Create the AlertDialog object and return it
return builder.create();
}
}

最佳答案

改变

import android.support.v7.app.AlertDialog;

import android.app.AlertDialog;

关于android - fragment 对话框使应用程序崩溃,还有其他解决方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30277772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com