ActionBarSherlock不支持光的主题警报对话框? [英] ActionBarSherlock doesn't support light-theme alert dialogs?

查看:297
本文介绍了ActionBarSherlock不支持光的主题警报对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那么正如标题所说,我使用的actionBarSherlock库和光的主题,有时我需要使用alertDialog.Builder类显示一个对话框。

Well as the title says, i'm using the actionBarSherlock library and a light theme, and sometimes I need to show a dialog using the alertDialog.Builder class.

事情是,无论我怎么努力,这个主题并不适用于对话框本身。主题应该在这两个新的API和旧的(之前的蜂窝状)。

Thing is, no matter what I try, the theme doesn't apply to the dialog itself. The theme should work on both new APIs and old ones (prior to honeycomb).

例如:

code:

final AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(activity,
            R.style.AppTheme_LightDialog));

final AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(activity,
            R.style.Theme_Sherlock_Light_Dialog));

XML:

<style name="AppTheme_LightDialog" parent="@android:style/Theme.Light">
    <item name="android:windowFrame">@null</item>
    <item name="android:windowTitleStyle">@style/DialogWindowTitle.Sherlock.Light</item>
    <item name="android:windowBackground">@drawable/abs__dialog_full_holo_light</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowActionModeOverlay">true</item>
    <item name="android:windowCloseOnTouchOutside">true</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:backgroundDimAmount">0.6</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
    <item name="android:textColorPrimary">@color/abs__primary_text_holo_light</item>
    <item name="android:textColorPrimaryInverse">@color/abs__primary_text_holo_dark</item>
    <item name="windowMinWidthMajor">@dimen/abs__dialog_min_width_major</item>
    <item name="windowMinWidthMinor">@dimen/abs__dialog_min_width_minor</item>
    <item name="windowActionBar">false</item>
    <item name="windowContentOverlay">@null</item>
    <item name="android:textAppearance">?android:attr/textAppearanceInverse</item>
</style>

我知道我可以使用dialogFragment,但有另一种方式?该对话框是非常简单的,因为有很多人,这将是恼人的修改它们。

I know i can use the dialogFragment, but is there another way? the dialogs are quite simple, and as there are many of them, it would be annoying to change them all.

编辑:我可能是错的,但似乎使用了android:alertDialogStyle属性(如图所示的这里)改变其旧的API,但它并没有太多的定制。事实上,它仅支持颜色,我不知道如何设置,甚至文字的颜色(的标题和/或邮件)。

I might be wrong, but it seems that using the android:alertDialogStyle attribute (shown here) changes it for old APIs , but it doesn't have a lot of customization. In fact, it supports only colors, and I'm not sure how to set even the text color (of the title and/or the message).

推荐答案

研究了一下之后,我觉得这不是一个ActionBarScherlock问题,但在警报对话框中一个光主题的问题。让我们尝试一些事情:

After researching a bit, I think it's not an ActionBarScherlock issue, but a Light Theme issue in alert dialogs. Let's try some things:

使用:

final AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.AppTheme_LightDialog));

修改

<style name="AppTheme_LightDialog" parent="@android:style/Theme.Light">

要:

<style name="AppTheme_LightDialog" parent="@android:style/Theme.Dialog">

然后覆盖默认Theme.Dialog风格(复制粘贴在Android的Git树):

Then override the default "Theme.Dialog" styles (copy-pasted from the Android git tree):

<style name="AppTheme_LightDialog" parent="@android:style/Theme.Dialog">
    <item name="android:windowFrame">@null</item>
    <item name="android:windowTitleStyle">@android:style/DialogWindowTitle</item>
    <item name="android:windowBackground">@android:drawable/panel_background</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
</style>

您可能需要复制原来的资源(@android:款式/ DialogWindowTitle,@android:款式/ Animation.Dialog和@android:绘制/ panel_background)到项目

You may need to copy the original resources (@android:style/DialogWindowTitle, @android:style/Animation.Dialog and @android:drawable/panel_background) to your project.

最后,从肖恩Castrianni棘手的部分( ),因为它似乎机器人需要一些额外的帮助样式正确地应用到AlertDialog的文本。添加到您的AppTheme_LightDialog的风格:

And finally, the tricky part (from Shawn Castrianni ), as it seems Android needs some extra help to apply correctly a style to AlertDialog's text. Add to your "AppTheme_LightDialog" style:

<item name="android:textColor">?android:attr/textColorPrimaryInverseDisableOnly</item>

更新:

看来,以蜂窝文本样式之前没有实际应用于AlertDialogs。上述code为您提供了一个解决方案,> =蜂窝设备。还有一个有趣的解决方法,使之可以在这些设备的工作(检查和<一href="http://stackoverflow.com/questions/2422562/how-to-change-theme-for-alertdialog/5392617#5392617">this),但你可能要开始问你,如果你preFER不同的方法,它需要较少的工作。

It seems that prior to Honeycomb text styling is not actually applied to AlertDialogs. The above code gives you a solution to >=Honeycomb devices. There's an interesting work-around to make it work also in those devices (check this and this), but you may want to start asking you if you prefer a different approach which requires less work.

顺便说一句,我不知道,如果它是你的情况,但你也可以使用相同的ContextThemeWrapper如果膨胀的AlertDialog的自定义布局是很重要的。例如,

BTW, I'm not sure if it's your case, but it's important that you also use the same ContextThemeWrapper if you inflate a custom layout for the AlertDialog. For example,

修改

View view = View.inflate(activity, R.layout.myDialog, null);

要:

View view = View.inflate(new ContextThemeWrapper(activity, R.style.AppTheme_LightDialog), R.layout.myDialog, null);

这篇关于ActionBarSherlock不支持光的主题警报对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆