[英]Android/Java: How to add icon in my bottom bar dynamically
我想通过将它放在一个包含所有图标图像的文件夹的文件路径中动态地在我的底部栏中添加图标(以避免每次编译应用程序)。 我找到了这张票,但我真的不明白如何修改它......
@Override
public void run() {
Menu menu = bottomNavigation.getMenu();
if (menu.size() == 0) {
MenuMap = new ArrayMap<String, Integer>();
for (int i = 0; i < myitems_detail.length(); i++) {
try {
JSONObject obj = myitems_detail.getJSONObject(i);
if (obj.getString("ICONE") != null) {
int imgID = mContext.getResources().getIdentifier(obj.getString("ICONE"), "drawable", mContext.getPackageName());
MenuItem myItem = menu.add(0, obj.getInt("PAGE_ORDER"), 0, obj.getString("MENU_NAME"))
.setIcon(imgID);
MenuMap.put(obj.getString("MENU_NAME"), obj.getInt("id"));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
有任何想法吗? 提前致谢。
我认为这对你有用,但这种情况下你必须输入文件的完整路径也使用它的任何 Web Url
Uri filePath = null;
通过这里 Url 或
filePath = Uri.parse("String file location or url");
Bitmap myBitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
myMenuItem.setIcon(new BitmapDrawable(getResources(), myBitmap));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.