相关疑难解决方法(0)

创建快捷方式:如何使用drawable作为Icon?

下面是我的代码,用于创建所选应用程序的快捷方式.我真的没问题,应用程序工作得很好.

问题是我能够从我的应用程序创建一个带有ressource的快捷方式:

    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));
Run Code Online (Sandbox Code Playgroud)

但我真的想要一个定制的drawable.(Drawable myDrawable = .....)

我能怎么做?

   ResolveInfo launchable=adapter.getItem(position);
   final Intent shortcutIntent = new Intent();
    ActivityInfo activity=launchable.activityInfo;
    ComponentName name=new ComponentName(activity.applicationInfo.packageName,activity.name);       
    shortcutIntent.setComponent(name);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    final Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    // Sets the custom shortcut's title
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, launchable.loadLabel(pm));
    // Set the custom shortcut icon
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));

    // add the shortcut
    intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    sendBroadcast(intent);
    finish();
Run Code Online (Sandbox Code Playgroud)

非常感谢任何线索

icons android shortcut drawable android-intent

6
推荐指数
1
解决办法
6033
查看次数

在Android上获取正确的Laucher图标大小

我正在开发一个能够在主屏幕上添加快捷方式图标的应用程序.Android平板电脑的正确图标大小是多少?(或者更好地说,如何在运行时获取它?)它似乎与页面上的内容不同.我已打开DisplayMetrics.densityDpi并相应地更改图标大小.但它并不适用于所有设备DisplayMetrics.DENSITY_MEDIUM.Gnex 似乎没问题,但是我的Galaxy Tab同时显示48x48px图标(因为它在指南中),但是通常的启动器图标是72x72像素而不是48x48 - 它与指南不同?它是否可能与TouchWiz UI相关,因此它与纯Android不同?或问题出在哪里?另外值得注意的是,应用程序本身显示正确的启动器图标(它从hdpi文件夹中获取图标),但在运行时它看起来像是mdpi设备:/谢谢

icons android android-launcher

2
推荐指数
1
解决办法
2687
查看次数