TextDrawable 是一个可以将纯文本生成Drawable的类库,你可以将这个Drawable设置给ImageView,从而可将文字转为图片。这在某些场合是很有用的。
效果图:
如何使用你可在xml中创建个ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/imageView"/>
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/imageView2"/>
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/imageView3"/>
2. 然后生成Drawable设置到ImageView上imageView = (ImageView)this.findViewById(R.id.imageView);
TextDrawable drawable = TextDrawable.builder().buildRect("L", Color.RED);//创建矩形的
imageView.setImageDrawable(drawable);
imageView2 = (ImageView)this.findViewById(R.id.imageView2);
drawable = TextDrawable.builder().buildRound("A", Color.YELLOW);//创建圆形的
imageView2.setImageDrawable(drawable);
imageView3 = (ImageView)this.findViewById(R.id.imageView3);
drawable = TextDrawable.builder().buildRoundRect("1", Color.GREEN, 15);//创建圆角的
imageView3.setImageDrawable(drawable);