当基于AppCompat

时间:2016-12-15 08:42:07

标签: android android-appcompat android-theme illegalstateexception

我试图通过此代码在Fragment上显示AlterDialog,但是我收到错误:

 java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

清单:

<activity
    android:name=".Views.Activities.Main.ActivityMain"
    android:theme="@style/AppTheme"
    android:screenOrientation="portrait"
    android:windowSoftInputMode="adjustResize|stateHidden"/>

风格:

<style name="AppTheme" parent="Theme.AppCompat">
    <item name="colorPrimary">@color/signal_toolbar_color</item>
    <item name="colorPrimaryDark">@color/signal_secondary_color</item>
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="windowActionBarOverlay">false</item>
    <item name="android:windowIsFloating">false</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>

我该如何解决这个问题?我的ActivityMain样式基于AppCompat,我想知道为什么我会遇到这个问题

更新:

new AlertDialog.Builder(context)
        .setPositiveButton(R.string.button_allow, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(@NonNull DialogInterface dialog, int which) {
                request.proceed();
            }
        })
        .setNegativeButton(R.string.button_deny, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(@NonNull DialogInterface dialog, int which) {
                request.cancel();
            }
        })
        .setCancelable(false)
        .setMessage(messageResId)
        .show();

0 个答案:

没有答案