Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
110 views
in Technique[技术] by (71.8m points)

android - Styles won't change Title text and Button highlight animator colour in Cast Introductory Overlay

According to the documentation, Cast Introductory overlay is customizable via Styles.

<item name="castIntroOverlayStyle">@style/CustomCastIntroOverlay</item>
<style name="CustomCastIntroOverlay" parent="CastIntroOverlay">
    <item name="castButtonTextAppearance">@style/TextAppearance.CustomCastIntroOverlay.Button</item>
    <item name="castTitleTextAppearance">@style/TextAppearance.CustomCastIntroOverlay.Title</item>
</style>
<style name="TextAppearance.CustomCastIntroOverlay.Button" parent="android:style/TextAppearance">
    <item name="android:textColor">#FFFFFF</item>
</style>
<style name="TextAppearance.CustomCastIntroOverlay.Title"parent="android:style/TextAppearance.Large">
    <item name="android:textColor">#FFFFFF</item>
</style>

However, no matter what colour you put in the styles, the TitleText and Cast Button overlay colour (the one surrounding the button) does not change.

This is reproducible in the sample code also.

I have reported the bug in the repo

question from:https://stackoverflow.com/questions/65910371/styles-wont-change-title-text-and-button-highlight-animator-colour-in-cast-intr

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I managed to solve the issue with a hack:

                val overlay = IntroductoryOverlay.Builder(this@CastActivity, it)
                    .setTitleText(configHolder.tr("cast.message.overlay"))
                    .setOverlayColor(R.color.imageOverlayBackground)
                    .setSingleTime()
                    .build()

                overlay.show()

                // A hack to change colors. Note that the color of button itself is changed in the Styles
                (overlay as? ViewGroup)?.apply {
                    // Title text color
                    findViewById<TextView>(R.id.cast_featurehighlight_help_text_header_view)?.setTextColor(configHolder.getColor(R.color.imageOverlayParagraphForeground, 0.9F))
                    // The highlight color surrounding the button
                    findViewById<View>(R.id.cast_featurehighlight_view).apply {
                        try {
                            val classFields = this::class.java.declaredFields
                            for (classField in classFields) {
                                // Getting class member that is InnerZoneDrawable
                                if (classField.type.toString().contains("InnerZoneDrawable", true)) {
                                    classField.isAccessible = true
                                    // Get an object of this class member, convert it to Drawable, and apply color filter
                                    val innerZoneDrawable = classField.get(this)
                                    (innerZoneDrawable as Drawable).apply {
                                        colorFilter = PorterDuffColorFilter(configHolder.getColor(R.color.buttonPrimaryDefaultBackground), PorterDuff.Mode.SRC_IN)
                                    }

                                    // Now for the circle animator, we need to access Paint variables inside InnerZoneDrawable and apply color filter
                                    val innerZoneClassFields = innerZoneDrawable.javaClass.declaredFields

                                    for (innerZoneClassField in innerZoneClassFields) {
                                        if (innerZoneClassField.type == Paint::class.java) {
                                            innerZoneClassField.isAccessible = true
                                            (innerZoneClassField.get(innerZoneDrawable) as Paint).apply {
                                                colorFilter = PorterDuffColorFilter(configHolder.getColor(R.color.buttonPrimaryDefaultBackground), PorterDuff.Mode.SRC_IN)
                                            }
                                        }
                                    }
                                }
                            }
                        } catch (e: Exception) {
                            Timber.w(e)
                        }
                    }
                }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...