样式不会更改 Cast Introductory Overlay 中的标题文本和按钮突出显示动画颜色

Posted

技术标签:

【中文标题】样式不会更改 Cast Introductory Overlay 中的标题文本和按钮突出显示动画颜色【英文标题】:Styles won't change Title text and Button highlight animator colour in Cast Introductory Overlay 【发布时间】:2021-01-26 22:45:55 【问题描述】:

根据documentation,演员介绍覆盖可通过样式自定义。

<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>

但是,无论您在样式中添加什么颜色,TitleText 和 Cast Button 叠加颜色(按钮周围的颜色)都不会改变。

这在sample code 中也可以重现。

我有reported the bug in the repo

【问题讨论】:

【参考方案1】:

我设法通过 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)
                        
                    
                

【讨论】:

以上是关于样式不会更改 Cast Introductory Overlay 中的标题文本和按钮突出显示动画颜色的主要内容,如果未能解决你的问题,请参考以下文章

Introductory: Seeing through Statistics - Part 1

为啥我的 AppBar MUI 样式组件在状态更改时不会更改样式?

更改 UITableViewCell 样式会导致点击操作不会发生

SwiftUI:具有计时器样式的文本在提供的日期更改后不会更新

转换为枚举类型需要显式转换(static_cast、C 样式转换或函数样式转换)

Google Cast SDK 开发者控制台