gpt4 book ai didi

android - Jelly Bean 通知中的两种状态操作按钮

转载 作者:行者123 更新时间:2023-11-30 03:26:49 25 4
gpt4 key购买 nike

我正在尝试在我的通知中实现媒体播放器控件。我需要播放/暂停按钮在“播放”可绘制对象和“暂停”可绘制对象之间动态切换(基本上取决于用户的触摸)。例如,一旦用户触摸“暂停”按钮,它需要更改为“播放”。当用户触摸“播放”按钮时,它需要更改回“暂停”。

我假设最好的方法是创建一个 StateListDrawable XML 并将其设置为操作按钮的可绘制对象。不幸的是,我似乎无法让 StateListDrawable 工作。这是我的可绘制对象的 XML 文件:

<?xml version="1.0" encoding="utf-8"?>  
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_first="true"
android:drawable="@drawable/pause_track_notification" />
<item android:state_last="true"
android:drawable="@drawable/play_track_notification" />
</selector>

我是否遗漏了 XML 中的任何重要内容?现在,我只是得到一个应该显示播放/暂停按钮的空白区域。我如何让它工作?谢谢!

最佳答案

将其用于切换按钮和以下选择器:

<?xml version="1.0" encoding="utf-8"?>  
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="true"
android:drawable="@drawable/pause_track_notification" />
<item android:state_checked="false"
android:drawable="@drawable/play_track_notification" />
<item android:drawable="@drawable/play_track_notification" /> <!-- the default -->
</selector>

关于android - Jelly Bean 通知中的两种状态操作按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18101858/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com