连接时显示不同的chromecast操作栏图标



我在应用程序中集成了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_olo_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_olo_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中找到该文件的默认版本(以及引用的drawables)。

最新更新