android - 如何以编程方式增加Android中快捷图标的大小
问题描述
在我的应用程序中,我使用下面的代码来创建快捷方式。
public void createShortcut(Intent intent) {
Intent.ShortcutIconResource iconResource = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
Bitmap icon = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
String shortcutLabel = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Intent shortIntent = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
if (icon == null) {
if (iconResource != null) {
Resources resources = null;
try {
resources = pm.getResourcesForApplication(iconResource.packageName);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
if (resources != null) {
int id = resources.getIdentifier(iconResource.resourceName, null, null);
if (resources.getDrawable(id) instanceof StateListDrawable) {
Drawable d = (resources.getDrawable(id)).getCurrent();
icon = ((BitmapDrawable) d).getBitmap();
} else
icon = ((BitmapDrawable) resources.getDrawable(id)).getBitmap();
}
}
}
if (shortcutLabel != null && shortIntent != null && icon != null) {
ShortcutSerializableData objectData = AppSharedPref.getInstance().getShortcutSerializableData();
if (objectData == null) {
objectData = new ShortcutSerializableData();
Log.e(TAG, "Serialized data not found");
}
if (objectData.apps == null) {
objectData.apps = new ArrayList();
Log.e(TAG, "Serialized app not found");
}
ShortcutPac pacToAdd = new ShortcutPac();
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
if (x >= (width - 250)) {
y = y + 150;
x = 40;
}
pacToAdd.x = x;
pacToAdd.y = y;
pacToAdd.URI = shortIntent.toUri(0);
pacToAdd.label = shortcutLabel;
pacToAdd.icon = icon;
x = x + 250;
if (HomeActivity.activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
pacToAdd.landscape = true;
else
pacToAdd.landscape = false;
pacToAdd.cacheIcon();
objectData.apps.add(pacToAdd);
pacToAdd.addToHome(this, homeView);
AppSharedPref.getInstance().setShortcutSerializableData(objectData);
}
}
上面的代码正在按预期工作并创建捷径。我的问题是可以改变快捷图标的大小吗?我的意思是通过上面的代码,我得到了图标的大小(例如 50x50),然后我得到了与 7 英寸和 10 英寸平板电脑上的快捷图标相同的大小。我想要的是更改平板电脑快捷图标的大小。我想显示比平常更大的平板电脑快捷方式图标,因为它是为手机创建的。
注意:在 Android 操作系统的设置中,如果我选择显示选项,我可以从那里增加图标和文本的大小。但是我想要同样的事情,我想以编程方式更改快捷图标的大小。可能吗?任何帮助将不胜感激。
解决方案
图标显示大小取决于启动器。幸运的是,您无法强制执行用户想要的不同大小。
推荐阅读
- jquery - ajax POST 用于包含带有 jQuery 和 Django 的数组的数据
- sql - 根据 SQL 中的日期从同一列的总和中减去
- c# - Azure 函数和 ASP.NET 成员资格
- shell - 删除包含存储在变量中的字符串的行在 sed 中不起作用
- vba - 用户表单在多个 Word 文档中填写书签?
- python - 无头 python 脚本需要 x-server 才能运行
- docker - Dockerize 非 Maven JEE 应用程序
- html - 从文件浏览器中选择多个文件时,HTML 多文件输入挂起
- asp.net-mvc - 如何在我的内容中添加新页面
- c - 自动化 C 程序的用户输入