How to change the blue line in AlertDialog (Holo theme)

I want to change the color of the blue Header and the blue line that is included in the AlertDialog (Holo theme), I managed to change the Title color by looking at android styles.xml and themes.xml, but I can not find a property or style that I can use / change to change the color of my XML.

Below is the style that I use to change the color of the title

<style name="myAlertDialog" parent="android:Theme.Holo.Dialog"> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowTitleStyle">@style/myAlertDialogTitleStyle</item> </style> <style name="myAlertDialogTitleStyle"> <item name="android:maxLines">1</item> <item name="android:scrollHorizontally">true</item> <item name="android:textAppearance">@style/myAlertDialogTitleStyleTextAppearance</item> </style> <style name="myAlertDialogTitleStyleTextAppearance"> <item name="android:textSize">22sp</item> <item name="android:textColor">#ffff8800</item> </style> 
+6
source share
3 answers

EDIT: I made a mistake in my original answer.

Unfortunately, the styles used for dialogs are internal and cannot be used in the same way as some other simple holographic controls. I created an open source project to handle this in very simple situations (I hope to extend it along the way and make it more ... legal). Here is a link to a new answer that describes this in more detail: How to change the color of the AlertDialog header and the color of the line below


For posterity, here is my naive old answer:

Take a look at the answer posted here . For your specific purpose, you will want to redefine the dialogTitleDecorLayout ( I think! ) Style as opposed to the listSeparatorTextViewStyle style.

If you are interested where it was originally installed, you can pull out the themes.xml file into your sdk folder on your computer and find the dialogTitleDecorLayout attribute. This should result in a dialog_title_holo layout dialog_title_holo , which should also be on your computer. There you should find the following code in the layout:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:fitsSystemWindows="true"> <TextView android:id="@android:id/title" style="?android:attr/windowTitleStyle" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="60dip" android:paddingLeft="32dip" android:paddingRight="32dip" android:gravity="center_vertical|left" /> <ImageView android:id="@+id/titleDivider" android:layout_width="match_parent" android:layout_height="4dip" android:scaleType="fitXY" android:gravity="fill_horizontal" android:paddingLeft="16dip" android:paddingRight="16dip" android:src="@android:drawable/divider_strong_holo" /> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical" android:foreground="?android:attr/windowContentOverlay"> <FrameLayout android:id="@android:id/content" android:layout_width="match_parent" android:layout_height="match_parent" /> </FrameLayout> </LinearLayout> 

The note code is the @android:drawable/divider_strong_holo link @android:drawable/divider_strong_holo . This file also exists on your computer, and it should be blue 9patch. You will need to create a similar 9patch of a different color. Good luck Even if this is not quite the right attribute, I think you see what you might need here ...

+4
source

After some messing around, I came up with a way to archive the dialog the moment it is displayed:

 private AlertDialog showWithThemeColors() { Log.d(TAG, "showWithThemeColors()"); AlertDialog dialog = this.builder.show(); try { ViewGroup decorView = (ViewGroup) dialog.getWindow().getDecorView(); FrameLayout windowContentView = (FrameLayout) decorView.getChildAt(0); FrameLayout contentView = (FrameLayout) windowContentView.getChildAt(0); LinearLayout parentPanel = (LinearLayout) contentView.getChildAt(0); LinearLayout topPanel = (LinearLayout) parentPanel.getChildAt(0); View titleDivider = topPanel.getChildAt(2); LinearLayout titleTemplate = (LinearLayout) topPanel.getChildAt(1); TextView alertTitle = (TextView) titleTemplate.getChildAt(1); int textColor = this.context.getResources().getColor(R.color.customer_text_on_primary); alertTitle.setTextColor(textColor); int primaryColor = this.context.getResources().getColor(R.color.customer_primary); titleDivider.setBackgroundColor(primaryColor); } catch (Exception e) { Log.e(TAG, "showWithThemeColors() - Could not re-brand dialog with theme colors.", e); } return dialog; } 

Please note that this solution may break at any time when the basic layout of the system for dialogue changes. Nevertheless, this is an original system dialogue with all the advantages of such a solution.

+4
source

There is a library that does just that for all of your dialogs:

https://github.com/inmite/android-styled-dialogs

+1
source

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


All Articles