android - 连接时不同的 chromecast 操作栏图标

标签 android chromecast google-cast

我在我的应用程序中集成了 chromecast。当连接和未连接 chromecast 时,我想要不同的操作栏图标。我创建了一个可绘制的 mr_ic_media_route_holo_light.xml 并在其中添加了以下代码以用于 chromecast 图标它没有连接。但是连接时我需要为不同的 chromecast 图标添加什么?我尝试创建 xml-'ic_media_route_connecting_holo_light.xmlmr_ic_media_route_connecting_holo_light.xml 用于显示图标当连接 chromecast 但它不起作用时。无论是否连接 chromecast,它都会显示相同的图标。我正在使用主题 Theme.AppCompat.Light。`

mr_ic_media_route_holo_light

  <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
        android:oneshot="false" >

        <item
            android:drawable="@drawable/ic_cast_white_24dp"
            android:duration="500"/>
        <item
            android:drawable="@drawable/ic_cast_white_24dp"
            android:duration="500"/>
        <item
            android:drawable="@drawable/ic_cast_white_24dp"
            android:duration="500"/>
        <item
            android:drawable="@drawable/ic_cast_white_24dp"
            android:duration="500"/>

    </animation-list>

最佳答案

您需要在可绘制对象中包含另一个 xml,并将其命名为 mr_ic_media_route_holo_light.xml。其默认内容是:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:state_enabled="true"
            android:drawable="@drawable/mr_ic_media_route_on_holo_light" />
    <item android:state_checkable="true" android:state_enabled="true"
            android:drawable="@drawable/mr_ic_media_route_connecting_holo_light" />
    <item android:state_enabled="true"
            android:drawable="@drawable/mr_ic_media_route_off_holo_light" />
    <item android:drawable="@drawable/mr_ic_media_route_disabled_holo_light" />
</selector>

并更新内容以指向您想要的内容。请注意,此文件(以及引用的可绘制对象)的默认版本可以在您的 <SDK-DIR>/extras/android/support/v7/mediarouter/res/drawable 中找到。 .

关于android - 连接时不同的 chromecast 操作栏图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28495964/

相关文章:

java - Android - 设置应用程序背景

android - 在 Android 上使用 Hazelcast 会产生随机错误

java - Android Studio 3.2- “Waiting for build to finish”&无法下载gradle.jar

android - 使用图标和文本创建自定义按钮

android - Google Chromecast接收器无法同时播放音频

android - 不允许启动服务

javascript - 如果未安装 Chromecast 扩展程序或使用隐身模式,则 Google Chromecast 发件人错误

android - 将我的 Android 应用程序中的 Youtube 视频直接转换到 Youtube(在 chromecast 或 roku 或电视中)

ios - Chromecast 无法播放保存的视频

ios - Chromecast 网络 I/O 错误