Search code examples
androidchromecastgoogle-cast

Different chromecast action bar icon when it is connected


I have integrated chromecast in my app.I want different action bar icons when chromecast is connected and not connected.I have created a drawable mr_ic_media_route_holo_light.xml and added below code to it for chromecast icon when it is not connected.But what i need to add for different chromecast icon when it is connected?I tried creating xml-'ic_media_route_connecting_holo_light.xmlandmr_ic_media_route_connecting_holo_light.xmlfor showing icon when chromecast is connected but it doesn't work.It shows same icon when chromecast is connected or not.I am using theme 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>

Solution

  • You need to include another xml in your drawable, and call it mr_ic_media_route_holo_light.xml. The default content for that is:

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

    and update the content of that to point to what you would like. Note that the default version of this file (and the referenced drawables) can be found in your <SDK-DIR>/extras/android/support/v7/mediarouter/res/drawable.