使用 NoActionBar 时 AppCompat 主题错误
AppCompat Theme Error when using NoActionBar
我正在为我的整个应用程序使用工具栏。所以我已经将我的应用程序主题设置为 Theme.AppCompat.Light.NoActionBar 但是我需要在我的应用程序的一部分中显示一个警告对话框。当我尝试显示警报对话框时,出现关于 Theme.Appcompat
的运行时错误
我的manifest.xml文件
<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>
我该怎么办
感谢帮助
如果没有看到您实际创建 Dialog
的代码,很难判断,但我猜您是:
- 创建
Dialog
时不使用 Activity
作为 Context
。 Activity
上下文包含主题;如果您尝试使用 Application
它不会获得正确的主题。
- 将您的
Dialog
主题设置为不继承自 Theme.AppCompat
的内容(使用构造函数,setStyle()
或 ContextThemeWrapper
)。
无论如何,Dialog
无法获得 Theme.AppCompat
提供的必需属性。
我正在为我的整个应用程序使用工具栏。所以我已经将我的应用程序主题设置为 Theme.AppCompat.Light.NoActionBar 但是我需要在我的应用程序的一部分中显示一个警告对话框。当我尝试显示警报对话框时,出现关于 Theme.Appcompat
的运行时错误我的manifest.xml文件
<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>
我该怎么办 感谢帮助
如果没有看到您实际创建 Dialog
的代码,很难判断,但我猜您是:
- 创建
Dialog
时不使用Activity
作为Context
。Activity
上下文包含主题;如果您尝试使用Application
它不会获得正确的主题。 - 将您的
Dialog
主题设置为不继承自Theme.AppCompat
的内容(使用构造函数,setStyle()
或ContextThemeWrapper
)。
无论如何,Dialog
无法获得 Theme.AppCompat
提供的必需属性。