Android: Cast MiniControllerFragment自定义

Android: Cast MiniControllerFragment customization

我正在尝试自定义 castBackground 和 castProgressBarColor MiniControllerFragment 属性,如官方文档中所述: https://developers.google.com/cast/docs/android_sender_advanced

我为我的 Activity 使用以下样式:

 <style name="AppTheme.NoActionBarNoTitle" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="castIntroOverlayStyle">@style/CustomCastIntroOverlay</item>
    <item name="castMiniControllerStyle">@style/CustomCastMiniController</item>
</style>

这是 CustomCastMiniController 样式:

   <style name="CustomCastMiniController" parent="CastMiniController">
    <item name="castShowImageThumbnail">true</item>
    <item name="castTitleTextAppearance">@style/TextAppearance.AppCompat.Subhead</item>
    <item name="castSubtitleTextAppearance">@style/TextAppearance.AppCompat.Caption</item>
    <item name="castBackground">#FFFFFF</item>
    <item name="castProgressBarColor">#FFFFFF</item>
</style>

我无法构建,因为这些错误:

Error:(2073, 21) No resource found that matches the given name: attr 'castBackground'.
Error:(2074, 21) No resource found that matches the given name: attr 'castProgressBarColor'.

如果我在我的 CustomCastMiniController 样式应用程序中删除这两个属性,则会成功启动。

您应该经常查看最常用的内容 version. In some cases it is needed to use the latest version because some functionality is not yet implemented in an older version. You have to open the project.properties file of the android-support-v7-appcompat and change the target to latest version。之后,清理并构建您的项目。

castBackgroundcastProgressBarColor 属性是在 Google Cast SDK 的更高版本中引入的,如 release notes:

中所示

Oktober 24, 2016

  • Added ability to customize the style of mini controllers: added castBackground for setting its background color, castButtonColor to color all buttons used in the mini controller, and castProgressBarColor to color the progress bar.

因此,请确保您在 build.gradle 文件中使用最新版本的 Google Cast SDK 进行编译(撰写本文时的版本为 10.0.0):

dependencies {
    compile 'com.android.support:appcompat-v7:25.0.1'
    compile 'com.android.support:mediarouter-v7:25.0.1'
    compile 'com.google.android.gms:play-services-cast-framework:10.0.0'
}

如果今天有人仍然面临同样的问题,在我的情况下,问题更简单一点:

  Originally I was declaring:
  <fragment
        android:id="@+id/castMiniController"
        class="....MiniControllerFragment"
         app:castBackground="#ffffff"

这导致背景变得透明,而不是:

       <fragment
        android:id="@+id/castMiniController"
        class="....MiniControllerFragment"
        app:castBackground="@color/saved_color"

允许您有效地设置当前颜色。希望对你有帮助。

在 colors.xml 中定义颜色并在 styles.xml 中将其定义为 #000000

的 @color/black 实例