Android阻止活动样式应用于alertdialogs
我的style.xml中有一些小的自定义项:Android阻止活动样式应用于alertdialogs,android,styles,android-alertdialog,Android,Styles,Android Alertdialog,我的style.xml中有一些小的自定义项: <style name="AppBaseTheme" parent="android:Theme.Holo.Light.NoActionBar"></style> <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <item name="android:backgro
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.NoActionBar"></style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:background">@color/light_grey</item>
<item name="android:textColor">@color/white</item>
</style>
有人能帮忙吗?有一个可行的解决方案-使用另一个
AlertDialog.Builder
构造函数,其主题如中所述,其思想基本上来自:
- 在你的风格中有一个奇怪的东西。xml:app主题定义了
,而不是android:background
。似乎没有理由这么做,因为如果所有视图都需要相同的背景(我怀疑这是可能的),那么就可以为视图设置一些基本主题。我认为,干扰应用程序主题和视图主题基本上不是一个好主意,因为应用程序需要完全不同的属性。那么,让我们做如下:android:windowBackground
这里请注意,由于某种原因,构造函数做得不对,<resources> <style name="AppBaseTheme" parent="android:Theme.Holo.Light.NoActionBar"></style> <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <item name="android:windowBackground">@color/light_grey</item> <item name="android:textColor">@color/white</item> </style> </resources>
是必要的(似乎这是因为并非所有属性都在主题中,主题仅使用ContextThemeWrapper“重新创建”)ContextThemeWrapper
<resources>
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.NoActionBar"></style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowBackground">@color/light_grey</item>
<item name="android:textColor">@color/white</item>
</style>
</resources>
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, android.R.style.Theme_Dialog));