我在我的应用程序中集成了 chromecast。当连接和未连接 chromecast 时,我想要不同的操作栏图标。我创建了一个可绘制的 mr_ic_media_route_holo_light.xml
并在其中添加了以下代码以用于 chromecast 图标它没有连接。但是连接时我需要为不同的 chromecast 图标添加什么?我尝试创建 xml-'ic_media_route_connecting_holo_light.xml
和 mr_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/