简体   繁体   English

通过Android中的可绘制对象或布局创建自定义图标

[英]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.

相关问题 从布局创建drawable - Create drawable from layout 使用不同的布局和键(不是矩形,从可绘制图像中选取形状)在Android中创建自定义键盘 - Create custom keyboard in android using different layout and keys not being rectangle, shape picked from the drawable image 自定义Resource文件夹名称,用于android中的layout,drawable .. - custom Resource folder names for layout,drawable .. in android 如何在可绘制布局上创建形状 android - How to create shapes on drawable layout android Android:自定义布局的图标大小 - Android: Icon Size for a custom layout 从Android菜单项图标中获取绘图 - get drawable from Android Menu Item Icon 形状可绘制的Android菜单图标 - Android menu icon from a shape drawable Android - 具有州列表背景的仪表板布局仅适用于图标 - Android - Dashboard layout with a statelist background drawable only for the icon 可绘制的Android自定义Seekbar - Android custom Seekbar from drawable Android:以编程方式设置区域设置会导致Google地图从错误的可绘制区域设置中加载自定义标记图标 - Android : Setting locale programmatically causes to google maps load custom marker icon from wrong drawable locale
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM