![](/img/trans.png)
[英]How to correctly set androidTheme in cordova-plugin-datepicker plugin
[英]How to set images in Cordova plugin
我正在将android本机代码转换为Cordova插件。 在本机我正在使用以下代码在浮动操作按钮中设置图像
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
floatingActionButton.setImageDrawable(getResources().getDrawable(R.drawable.icon_record, getTheme()));
} else {
floatingActionButton.setImageDrawable(getResources().getDrawable(R.drawable.icon_record));
}
我的疑问是,在android中我们将使用R.drawable.XXXXXX
来设置图像。 同样明智的我们如何在cordova插件中设置图像以及我们必须存储图像的位置(如android原生中的可绘制文件夹)
InAppBrowser插件的示例
Resources activityRes = cordova.getActivity().getResources();
int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName());
Drawable backIcon = activityRes.getDrawable(backResId);
if (Build.VERSION.SDK_INT >= 16)
back.setBackground(null);
else
back.setBackgroundDrawable(null);
back.setImageDrawable(backIcon);
使用plugin.xml中的resource-file标签复制图像
<resource-file src="src/android/res/drawable-hdpi/ic_action_previous_item.png" target="res/drawable-hdpi/ic_action_previous_item.png" />
<resource-file src="src/android/res/drawable-mdpi/ic_action_previous_item.png" target="res/drawable-mdpi/ic_action_previous_item.png" />
<resource-file src="src/android/res/drawable-xhdpi/ic_action_previous_item.png" target="res/drawable-xhdpi/ic_action_previous_item.png" />
<resource-file src="src/android/res/drawable-xxhdpi/ic_action_previous_item.png" target="res/drawable-xxhdpi/ic_action_previous_item.png" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.