android:如何从数据库为AlertDialog设置图标?

android:如何从数据库为AlertDialog设置图标?,第1张

概述所以我显示的AlertDialog是这样的:newAlertDialog.Builder(context).setMessage(message).setTitle(title).setCancelable(true).setIcon(R.drawable.ic_launcher)//seticon//morecode是否可以使用setIcon从db获取图标,例如联系人照片:DatabaseHelperdb

所以我显示的AlertDialog是这样的:

new AlertDialog.Builder(context)  .setMessage(message)  .setTitle(Title)  .setCancelable(true)  .setIcon(R.drawable.ic_launcher) // set icon  // more code@H_404_6@

是否可以使用setIcon从db获取图标,例如联系人照片:

DatabaseHelper db = new DatabaseHelper(context);        Cursor csr = db.getSpecialContact(number);csr.movetoFirst();String photo = csr.getString(csr.getColumnIndexOrThrow("photo_url"));Uri photo_url = Uri.parse(photo);@H_404_6@

我希望能够使用setIcon使用photo_url(保存在db like content://com.androID.contacts/data/1中),但当然它希望参数为int而不是string或Uri.可以实现吗?

解决方法:

这是如何:

Drawable drawable = null;try {    DatabaseHelper db = new DatabaseHelper(context);    Cursor csr = db.getSpecialContact(number);    csr.movetoFirst();    String photo = csr        .getString(csr.getColumnIndexOrThrow("photo_url"));    Uri photo_url = Uri.parse(photo);    Bitmap tempBitmap;    tempBitmap = BitmapFactory.decodeStream(context        .getContentResolver().openinputStream(photo_url));    // Convert bitmap to drawable    drawable = new BitmapDrawable(context.getResources(), tempBitmap);} catch (fileNotFoundException e) {    Bitmap bm = BitmapFactory.decodeResource(context.getResources(),        R.drawable.ic_launcher);    drawable = new BitmapDrawable(context.getResources(), bm);}new AlertDialog.Builder(context)    .setMessage(message)    .setTitle(Title)    .setCancelable(true)    .setIcon(drawable)@H_404_6@
总结

以上是内存溢出为你收集整理的android:如何从数据库为AlertDialog设置图标?全部内容,希望文章能够帮你解决android:如何从数据库为AlertDialog设置图标?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1107295.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)