我想创建类似于谷歌联系人应用程序的图标。
我希望提供背景颜色和文本并生成图标。
我目前正在尝试的是解决方案 here.
我正在使用 CircularImageView external library这似乎是问题所在。事实上,如果我尝试这样做:
CircularImageView imageView;
....
Drawable d = new TextDrawable("My Text", mycolor, textSize);
imageView.setImageDrawable(d);
我收到这个错误:
java.lang.IllegalArgumentException: width and height must be > 0
at android.graphics.Bitmap.createBitmap(Bitmap.java:829)
at android.graphics.Bitmap.createBitmap(Bitmap.java:808)
at android.graphics.Bitmap.createBitmap(Bitmap.java:775)
at com.pkmmte.view.CircularImageView.drawableToBitmap(CircularImageView.java:327)
如果我使用标准的 ImageView 它就可以工作。有什么建议吗?
最佳答案
我已经在GitHub上找到了一个库,可以实现你想要的效果:
TextDrawable
This light-weight library provides images with letter/text like the Gmail app. It extends the
Drawable
class thus can be used with existing/custom/networkImageView
classes. Also included is a fluent interface for creating drawables and a customizableColorGenerator
.
如果您希望创建自己的实现,请尝试仔细阅读该库的代码并逐步实现您自己的版本
希望对你有帮助
关于java - Android - CircularImageView setImageDrawable 以编程方式创建可绘制对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34643277/