[英]Create a custom icon from a drawable or layout in Android
I'm trying to create custom shortcut icons that, via Intents, call an activity inside my app. 我正在尝试创建自定义快捷方式图标,这些图标可以通过Intent在我的应用程序内调用活动。 The problem is that I want to create them either by modifying one of my app's drawables or (preferably) one of my layouts. 问题是我想通过修改应用程序的一个可绘制对象或(最好是)我的一个布局来创建它们。
For the drawables, I have tried this 对于绘画,我已经尝试过
Drawable iconDrawable = getResources().getDrawable(iconResource);
iconDrawable.mutate();
iconDrawable.setColorFilter(0xff00ff00, PorterDuff.Mode.SRC_ATOP);
BitmapDrawable bd = (BitmapDrawable) iconDrawable;
bd.mutate();
bd.setColorFilter(0xff00ff00, PorterDuff.Mode.SRC_ATOP);
putShortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bd.getBitmap());
but it doesn't work, the drawable is shown as-is, without modifying its color. 但它不起作用,可绘制对象按原样显示,而没有修改其颜色。
And as for creating the icon from a custom layout, which is what I really want to do... I simply don't know where to begin. 至于从自定义布局创建图标,这是我真正想要做的...我根本不知道从哪里开始。
Could anyone please tell me how to do it or at least point me in the right direction? 有人可以告诉我该怎么做,或者至少可以指出正确的方向吗?
Thanks! 谢谢!
Okay, I found the answer by studying the AnyCut source code, and the "trick" is to use a Canvas: 好的,我通过研究AnyCut源代码找到了答案,“诀窍”是使用Canvas:
http://code.google.com/p/apps-for-android/source/browse/AnyCut/src/com/example/anycut/CreateShortcutActivity.java http://code.google.com/p/apps-for-android/source/browse/AnyCut/src/com/example/anycut/CreateShortcutActivity.java
(more precisely, the generatePhoneNumberIcon function). (更确切地说,generatePhoneNumberIcon函数)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.