简体   繁体   中英

AppCompat Theme Error when using NoActionBar

I'm using a toolbar for my entire application. So I have set up my application Theme to Theme.AppCompat.Light.NoActionBar But I need to show a alert dialog in a part of my app. When I try to show alert dialog I'm getting Runtime error about Theme.Appcompat

在此处输入图片说明

My manifest.xml file

<application
    android:allowBackup="true"
    android:icon="@drawable/app_icon2"
    android:label="@string/app_name"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar"
    >
    <activity
        android:name="com.project.project.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.project.project.StActivity"
        android:configChanges="orientation|screenSize|keyboardHidden"
        android:label="@string/app_name">
        <intent-filter >
            <action android:name="android.intent.action.DEFAULT" />

            <category android:name="android.intent.category.LAUNCHER" />

        </intent-filter>
    </activity>



</application>

What should i do Thanks for help

It's hard to tell without seeing the code where you actually create the Dialog , but my guess is that you're either:

  1. Not using the Activity as the Context when you create the Dialog . The Activity context holds the theme; if you tried using the Application it wouldn't get the right theme.
  2. Setting your Dialog theme to something that doesn't inherit from Theme.AppCompat (using the constructor, setStyle() or ContextThemeWrapper ).

Either way, the Dialog doesn't get the required attributes provided by Theme.AppCompat .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM