ActionBarSherlock doesn't support light-theme alert dialogs?

天涯浪子 提交于 2019-11-30 23:52:15
Alejandro Colorado

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:

Use:

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

Change:

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

To:

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

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>

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

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>

UPDATE:

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.

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,

Change:

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

To:

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

This is what I did and it made the body of the dialog white. The title is still on a black background:

new AlertDialog.Builder(
    new ContextThemeWrapper(
        activity,
        R.style.Theme_Sherlock_Light));

I also tried Theme_Sherlock_Light_NoActionBar, but it doesn't seem to make any difference.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!