我做了一些研究,发现在展开的状态栏区域可以有一个进度条,但我仍然不确定是否可以使用动画图标。 我试过这个问题的答案:Animation in Notification bar Custom View .但是,该图标不是动画的。 如果不可能,您能否指出任何可以证实这一点的文件? 提前致谢。
最佳答案
您提到的问题中的视频(我承认我没有看到与我提供的链接之一相同)在那里清楚地显示了一个动画图标。大约在 0:35。 http://www.youtube.com/watch?v=yNcs-sS2nFU&t=0m32s (此链接跳转到该部分)。箭头有一条小黑线反复向下移动。对我来说似乎是动画。这是你想要的吗?
无论如何,Android 版本是什么?也许这是 T-Mobile 的一些定制,我不知道,这只是 YouTube 上的一些视频。
您可以为通知创建自定义 View ,例如:http://www.roman10.net/android-custom-notification-with-progress-bar/您可以对 animation drawable 使用类似的想法(同样的 SO 问题)Roman10 在哪里获得了默认的 android 图像。
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.noti);
contentView.setImageViewResource(... your animated resource ...);
编辑
据我所知,RemoteViews 最终不支持图像资源中的动画。但我找到了解决这个问题的方法,它可能很昂贵,但我还没有分析它以了解 CPU 使用情况。
我从 roman10(上面的链接)的代码开始,并做了一些修改。
yinyangAnim.xml + 动画帧.png文件
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="@drawable/yinyang0" android:duration="150" />
<item android:drawable="@drawable/yinyang1" android:duration="150" />
<item android:drawable="@drawable/yinyang2" android:duration="150" />
<item android:drawable="@drawable/yinyang3" android:duration="150" />
<item android:drawable="@drawable/yinyang4" android:duration="150" />
<item android:drawable="@drawable/yinyang5" android:duration="150" />
</animation-list>
添加另一个线程创建到开始按钮点击:
new Thread(new Runnable() {
public void run() {
int frameIndex = 0;
mRun = true;
while (mRun) {
++frameIndex;
SystemClock.sleep(100);
BitmapDrawable frame = (BitmapDrawable) yinyangAnimation.getFrame(frameIndex);
noti.contentView.setImageViewBitmap(R.id.status_icon, frame.getBitmap());
nm.notify(STATUS_BAR_NOTIFICATION, noti);
if (frameIndex >= yinyangAnimation.getNumberOfFrames()-1) {
frameIndex = 0;
}
}
}
}).start();
添加到 ProgressBarNotificationActivity.onCreate()
ImageView yinyang = new ImageView(this);
yinyang.setBackgroundResource(R.drawable.yinyang_anim);
yinyangAnimation = (AnimationDrawable) yinyang.getBackground();
当然还有私有(private)变量:private AnimationDrawable yinyangAnimation;
按下应用程序中的开始按钮并查看通知会为我显示旋转的阴阳。我在 loadinfo.net 上得到了阴阳,并使用 ImageMagick 命令行 (ubuntu) 将其拆分。
关于java - 是否可以在通知窗口(Android)上制作动画图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12324885/