Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android阻止活动样式应用于alertdialogs_Android_Styles_Android Alertdialog - Fatal编程技术网

Android阻止活动样式应用于alertdialogs

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.xml中有一些小的自定义项:

<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“重新创建”)


您是否已将AppBaseTheme应用于应用程序而非活动?
<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));