Remove grey background on Dialog with Custom theme that extends Theme.Dialog - android

I am using Accengage (Ad4Push) and I want to customize its dialog. Accengage team said that it is possible to change dialog style with custom theme and I did that. I can change textSize, textColor, windowBackground but I still see the grey color on Dialog. Please see my photo Here. (I haven't got enough reputations to post an image)
I want to change all background dialog to white, but I don't know which attribute I can use for this purpose.
This is the attribute I am using.
<style name="CustomDialogTheme" parent="#android:style/Theme.Dialog">
<item name="android:background">#color/background_holo_light</item>
<item name="android:divider">#color/background_holo_light</item>
<item name="android:dividerHorizontal">#null</item>
<item name="android:dividerVertical">#null</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:textColorPrimary">#android:color/black</item>
<item name="android:buttonBarButtonStyle">#style/CustomDialogTheme.Button</item>
<item name="android:padding">2dp</item>
<item name="android:windowBackground">#android:color/transparent</item>
</style>
<style name="CustomDialogTheme.Button">
<item name="android:background">#color/background_dark</item>
<item name="android:textColor">#color/background_holo_light</item>
<item name="android:layout_margin">8dp</item>
<item name="android:layout_marginLeft">16dp</item>
<item name="android:padding">8dp</item>
<item name="android:gravity">center</item>
</style>
How I can make background of dialog become white. (I only can change the style with custom style, can not change programmatically, because this dialog come from third party library)

In onCreate add this line.
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
checkout this post.
Dialog with transparent background in Android

Your question has already been answered here
Code from the link:
Add this to your styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.DoNotDim" parent="android:Theme">
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
And then apply the theme to your activity:
<activity android:name=".SampleActivity" android:theme="#style/Theme.DoNotDim">

add this line in your theme (thanks to AAA)
<item name="android:windowBackground">#android:color/transparent</item>
full style:
<style name="CustomDialogTheme" parent="#android:style/Theme.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:background">#color/background_holo_light</item>
<item name="android:divider">#color/background_holo_light</item>
<item name="android:dividerHorizontal">#null</item>
<item name="android:dividerVertical">#null</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:textColorPrimary">#android:color/black</item>
<item name="android:buttonBarButtonStyle">#style/CustomDialogTheme.Button</item>
<item name="android:padding">2dp</item>
</style>

Related

How to change ListPreference button colors?

I use bellow style to change Dialog background color to dark, In preference page I use ListPreference and after apply this style, cancel button of ListPreference disappeared in dialog background.
<style name="AppThemeBase" parent="Theme.MaterialComponents.DayNight">
<item name="colorPrimary">#212D3B</item>
<item name="colorPrimaryDark">#172331</item>
<item name="colorAccent">#61A3D7</item>
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="android:dialogTheme">#style/AppTheme.Dialog</item>
<item name="android:alertDialogTheme">#style/AppTheme.Dialog</item>
</style>
<style name="AppTheme.Dialog" parent="Theme.MaterialComponents.DayNight.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:background">#212D3B</item>
<item name="colorPrimary">#61A3D7</item>
<item name="colorPrimaryDark">#8DB2D3</item>
<item name="colorAccent">#61A3D7</item>
</style>
Is there a way to change this button color?
Finally I found solution. I don't understand what is different between android:alertDialogTheme and alertDialogTheme (without android:) but preference screen used the alertDialogTheme to stylize dialogs.
By adding bellow item to AppThemeBase, my problem is resolved.
<item name="alertDialogTheme">#style/AppTheme.Dialog</item>
Final AppThemeBase :
<style name="AppThemeBase" parent="Theme.MaterialComponents.DayNight">
<item name="colorPrimary">#212D3B</item>
<item name="colorPrimaryDark">#172331</item>
<item name="colorAccent">#61A3D7</item>
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="android:dialogTheme">#style/AppTheme.Dialog</item>
<item name="android:alertDialogTheme">#style/AppTheme.Dialog</item>
<item name="alertDialogTheme">#style/AppTheme.Dialog</item>
</style>
<style name="AppTheme.Dialog" parent="Theme.MaterialComponents.DayNight.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:background">#212D3B</item>
<item name="colorPrimary">#61A3D7</item>
<item name="colorPrimaryDark">#8DB2D3</item>
<item name="colorAccent">#61A3D7</item>
</style>

Android white text in search box

See attached
I am using a searchbar with the theme below (I know very little about Android themes, yet)
How do I make the text typed, in this case, "Hi Mom" white?
<style name="_Credential" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:editTextBackground">#drawable/credential_edit_text_holo_light</item>
<item name="android:textColorHighlight">#99005984</item>
<item name="android:textSelectHandleLeft">#drawable/credential_text_select_handle_left</item>
<item name="android:textSelectHandleRight">#drawable/credential_text_select_handle_right</item>
<item name="android:textSelectHandle">#drawable/credential_text_select_handle_middle</item>
<item name="android:autoCompleteTextViewStyle">#style/AutoCompleteTextViewCredential</item>
<item name="android:listChoiceIndicatorMultiple">#drawable/credential_btn_check_holo_light</item>
<item name="android:listChoiceIndicatorSingle">#drawable/credential_btn_radio_holo_light</item>
<item name="android:buttonStyle">#style/ButtonCredential</item>
<item name="android:imageButtonStyle">#style/ImageButtonCredential</item>
<item name="android:dropDownSpinnerStyle">#style/SpinnerCredential</item>
<item name="android:progressBarStyleHorizontal">#style/ProgressBarCredential</item>
<item name="android:seekBarStyle">#style/SeekBarCredential</item>
<item name="android:ratingBarStyle">#style/RatingBarCredential</item>
<item name="android:ratingBarStyleIndicator">#style/RatingBarBigCredential</item>
<item name="android:ratingBarStyleSmall">#style/RatingBarSmallCredential</item>
<item name="android:buttonStyleToggle">#style/ToggleCredential</item>
<item name="android:listChoiceBackgroundIndicator">#drawable/credential_list_selector_holo_light</item>
<item name="android:activatedBackgroundIndicator">#drawable/credential_activated_background_holo_light</item>
<item name="android:fastScrollThumbDrawable">#drawable/credential_fastscroll_thumb_holo</item>
</style>
<style name="_Credential" parent="android:Theme.Holo.Light.DarkActionBar">
...
<item name="android:editTextColor">#ffffff</item> <!--Allow to change the editText color-->
...
</style>
So you can't actually change the TextColor of something like a search box with android:textColor. Instead, you need to use the whole family of the textColor... attributes.
Create a custom style that has your main style as it's parent, and then change all three kinds of colors to be what you want. So, something like this:
<style name="master" paret="#android:Theme.Holo.Light.DarkActionBar">
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="android:textColorSecondary">#FFFFFF</item>
<item name="android:textColorTertiary">#FFFFFF</item>
</style>
Read more about this here.

Styling of AlertDialog buttons

In my application I use holoeverywhere. I would like to change the appearance of AlertDialog and I got stuck on buttons below alert dialog. I took a look how things were done in holoeverywhere and I tried to modify that.
Here is backtracking of my reasoning:
In theme there are atributes which define alertDialogTheme and some other stuff. We will come back later to selectableItemBackground also.
<style name="Holo.Base.Theme" parent="Theme.AppCompat">
...
<item name="alertDialogTheme">#style/Holo.Theme.Dialog.Alert</item>
...
<item name="buttonBarButtonStyle">?borderlessButtonStyle</item>
...
<item name="selectableItemBackground">#drawable/item_background_holo_dark</item> *
...
</sytle>
So i figure alertDialogStyle is my target which is further defined in styles:
<style name="Holo.Base.Theme.Dialog" parent="Holo.Theme">
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowAnimationStyle">#style/Holo.Animation.Dialog</item>
<item name="android:windowBackground">#drawable/dialog_full_holo_dark</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:windowTitleStyle">#style/Holo.DialogWindowTitle</item>
<item name="borderlessButtonStyle">#style/Holo.Button.Borderless.Small</item>
<item name="buttonBarStyle">#style/Holo.ButtonBar.AlertDialog</item>
<item name="listPreferredItemPaddingLeft">16dip</item>
<item name="listPreferredItemPaddingRight">16dip</item>
<item name="windowActionBar">false</item>
<item name="windowActionModeOverlay">true</item>
<item name="windowAnimationStyle">#style/Holo.Animation.Dialog</item>
<item name="windowContentOverlay">#null</item>
<item name="windowMinWidthMajor">#dimen/dialog_min_width_major</item>
<item name="windowMinWidthMinor">#dimen/dialog_min_width_minor</item>
<item name="windowNoTitle">true</item>
</style>
<style name="Holo.Theme.Dialog" parent="Holo.Base.Theme.Dialog" >
</style>
<style name="Holo.Theme.Dialog.Alert" parent="Holo.Theme.Dialog">
<item name="alertDialogStyle">#style/Holo.AlertDialog</item>
<item name="alertDialogTitleDividerColor">#color/holo_blue_light</item>
<item name="android:windowBackground">#android:color/transparent</item>
</style>
<style name="Holo.Button.Borderless" parent="Holo.Button">
<item name="android:background">?selectableItemBackground</item>
<item name="android:paddingLeft">4dip</item>
<item name="android:paddingRight">4dip</item>
</style>
So Holo.Theme.Dialog.Alert is inherited from Holo:base.Theme.Dialog which has an atribute for borderlessButtonStyle, which I guess defines the buttons of alert dialog.
Style Holo.Button.Borderless referes the atribute selectableItemBackground for its background. Atribute is set in application theme itself. So, my reasoning is if I inherit from theme Holo.theme and set selectableBackground atribut my change should reflect in customized alert dialog buttons and everything else where this background is used.
<style name="ThemeCustom" parent="#style/Holo.Theme>
…
<item name="selectableItemBackground">#drawable/custom_item_background </item>
…
</style>
But this does not work. No change is visible in alert dialog buttons. Is there something wrong with my reasoning?

How to style DialogPreference with a custom theme?

In my application I was using Theme.Holo and Theme.Holo.Light without any issues. When Holo theme is used and I click on a DialogPreference/ListPreference, a popped dialog is also themed with Holo. Same for the Holo.Light. But when PreferencesActivity is styled with my custom theme, which is derived from Holo.Light, all dialogs are themed with Holo.Light. I think I am missing somthing in my theme. Could anyone help me? Thanks a lot!
Here is my theme code:
<?xml version="1.0" encoding="utf-8"?>
<!-- Generated with http://android-holo-colors.com -->
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="GreenTheme" parent="android:Theme.Holo.Light">
<item name="android:editTextBackground">#drawable/edit_text_holo_light</item>
<item name="android:autoCompleteTextViewStyle">#style/AutoCompleteTextViewGreenTheme</item>
<item name="android:listChoiceIndicatorMultiple">#drawable/btn_check_holo_light</item>
<item name="android:listChoiceIndicatorSingle">#drawable/btn_radio_holo_light</item>
<item name="android:buttonStyle">#style/ButtonGreenTheme</item>
<item name="android:imageButtonStyle">#style/ImageButtonGreenTheme</item>
<item name="android:dropDownSpinnerStyle">#style/SpinnerGreenTheme</item>
<item name="android:tabWidgetStyle">#style/TabWidgetGreenTheme</item>
<item name="android:progressBarStyleHorizontal">#style/ProgressBarGreenTheme</item>
<item name="android:seekBarStyle">#style/SeekBarGreenTheme</item>
<item name="android:buttonStyleToggle">#style/ToggleGreenTheme</item>
<item name="android:listChoiceBackgroundIndicator">#drawable/list_selector_holo_light</item>
<item name="android:activatedBackgroundIndicator">#drawable/activated_background_holo_light</item>
<item name="android:fastScrollThumbDrawable">#drawable/fastscroll_thumb_holo</item>
<item name="android:actionBarStyle">#style/ActionBar.Solid.Greenactionbar</item>
<item name="android:buttonBarButtonStyle">#style/ButtonBarButtonStyleGreenTheme</item>
<item name="android:preferenceStyle">#style/TimePickerDialogFragmentGreen</item>
</style>
<style name="TimePickerDialogFragmentGreen" parent="#android:style/Theme.Holo.Light.Dialog">
<item name="android:editTextBackground">#drawable/edit_text_holo_light</item>
<item name="android:autoCompleteTextViewStyle">#style/AutoCompleteTextViewGreenTheme</item>
<item name="android:listChoiceIndicatorMultiple">#drawable/btn_check_holo_light</item>
<item name="android:listChoiceIndicatorSingle">#drawable/btn_radio_holo_light</item>
<item name="android:buttonStyle">#style/ButtonGreenTheme</item>
<item name="android:imageButtonStyle">#style/ImageButtonGreenTheme</item>
<item name="android:dropDownSpinnerStyle">#style/SpinnerGreenTheme</item>
<item name="android:tabWidgetStyle">#style/TabWidgetGreenTheme</item>
<item name="android:progressBarStyleHorizontal">#style/ProgressBarGreenTheme</item>
<item name="android:seekBarStyle">#style/SeekBarGreenTheme</item>
<item name="android:buttonStyleToggle">#style/ToggleGreenTheme</item>
<item name="android:listChoiceBackgroundIndicator">#drawable/list_selector_holo_light</item>
<item name="android:activatedBackgroundIndicator">#drawable/activated_background_holo_light</item>
<item name="android:fastScrollThumbDrawable">#drawable/fastscroll_thumb_holo</item>
<item name="android:actionBarStyle">#style/ActionBar.Solid.Greenactionbar</item>
<item name="android:buttonBarButtonStyle">#style/ButtonBarButtonStyleGreenTheme</item>
</style>
</resources>
I found this rather unformatted but otherwise nice answer.
The gist is that DialogPreferences are AlertDialogs created without the theme parameter, which means they apply which ever theme android:alertDialogTheme points to.
So I extended my theme like this to have the dialog themed:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/yellow_500</item>
<item name="colorPrimaryDark">#color/yellow_a700</item>
<item name="colorAccent">#color/purple_400</item>
<item name="android:alertDialogTheme">#style/DialogTheme</item>
</style>
<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorPrimary">#color/yellow_500</item>
<item name="colorPrimaryDark">#color/yellow_a700</item>
<item name="colorAccent">#color/purple_400</item>
<item name="android:windowMinWidthMinor">#android:dimen/dialog_min_width_minor</item>
</style>
</resources>
The colorPrimary, colorPrimaryDark and colorAccent in the AppTheme were the colours I wanted to have applied to the dialog as well.
Note that I needed the android:windowMinWidthMinor to prevent the dialog from collapsing horizontally.
I have clarifying questions, but can't ask them because of low rate. So: 1.Does your first style work correctly? 2.Are you sure, that theme #android:style/Theme.Holo.Light.Dialog has all items, you declared in TimePickerDialogFragmentGreen?For example:
<item name="android:tabWidgetStyle"> #style/TabWidgetGreenTheme</item>
3. Have you tried the idea proposed by Luksprog
And finally: I used something like that to create custom style for my EditTexts:
<style name="EditTextStyle" parent="#style/Indents">
<item name="android:textColor">#android:color/black</item>
<item name="android:background">#android:color/white</item>
<item name="android:textColorHint">#android:color/darker_gray</item>
<item name="android:textSize">14sp</item>
</style>
<style name="Indents" parent="#style/Margins">
<item name="android:paddingBottom">#dimen/activity_vertical_padding</item>
<item name="android:paddingTop">#dimen/activity_vertical_padding</item>
</style>
<style name="Margins">
<item name="android:layout_marginTop">#dimen/activity_vertical_margin </item>
<item name="android:layout_marginBottom">#dimen/activity_vertical_margin </item>
<item name="android:layout_marginLeft">#dimen/activity_horizontal_margin </item>
<item name="android:layout_marginRight">#dimen/activity_horizontal_margin </item>
</style>

Applying Styles Android

I want to make my Activity appear like a Dialog box, but without the title bar. So I think I should write this style myself.
But how should this XML style be?
I already tried the Theme.Dialog for my Activity, but the thing is, I don't want the background of the Theme.Dialog style. And without an label for screen.
I has all the screen build by XML, I want just center it on screen and has a semi-transparent outside background.
Just do this
<activity android:name=".MyActivity"
android:theme="#style/CustomTheme"
android:label="Gana"/>
res/values/styles.xml
<resources>
<style name="CustomTheme" parent="android:Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">#drawable/mybackground</item>
<item name="android:gravity">center</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowFrame">#null</item>
<item name="android:windowBackground">#android:color/transparent</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:backgroundDimEnabled">true</item>
<item name="android:background">#android:color/transparent</item>
</style>
If you don't want background remove that.

Categories

Resources