Does ActionBarSherlock not support easy topic alert dialogs?

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

The thing, no matter what I try, the topic does not apply to the dialogue itself. The theme should work both on new APIs and on old ones (up to cellular ones).

Example:

code:

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

or

 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> 

I know I can use dialogFragment, but is there any other way? the dialogs are quite simple, and since there are a lot of them, it would be very unpleasant to change all of them.


EDIT: Maybe I'm wrong, but using the android: alertDialogStyle attribute (shown here ) seems to change it for older APIs, but it doesn't have many settings. In fact, it only supports colors, and I'm not sure how to set even the color of the text (header and / or message).

+4
source share
2 answers

After a little research, I think this is not an ActionBarScherlock problem, but the Light Theme problem in the warning dialogs. Try a few things:

Using:

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

Edit:

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

To:

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

Then override the default styles "Theme.Dialog" (copied to 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 source resources (@android: style / DialogWindowTitle, @android: style / Animation.Dialog and @android: drawable / panel_background) to your project.

And finally, the hard part ( from Shawn Castrianni ), since it seems Android needs additional help to properly apply the style to the AlertDialog text. Add "AppTheme_LightDialog" to your style:

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

UPDATE:

Before cell text, the style doesn't seem to apply to AlertDialogs. The above code gives you a solution for> = cellular devices. There is interesting work to make it work on these devices too (check this and this ), but you can start asking if you prefer a different approach that requires less work.

By the way, I'm not sure if this is your business, but it is important that you also use the same ContextThemeWrapper if you are inflating a custom layout for AlertDialog. For instance,

Edit:

 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); 
+3
source

This is what I did, and made the body of the dialogue white. The name 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 that does not seem to make any difference.

+1
source

Source: https://habr.com/ru/post/1481205/


All Articles