作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
你好 friend ,我正在我的项目中使用compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'这个库,我想在
TextDrawable图标中添加前两个字符(如果有人的话)了解这个库请帮助如何在
TextDrawable图标中添加我的文本的前两个字符这是我的代码我的它只显示我的
TextView在
TextDrawable中的第一个字符` 图标,但我希望它显示前两个字符,请帮助我?
//get first letter of each String item
String firstLetter = String.valueOf(getItem(position).charAt(0));
ColorGenerator generator = ColorGenerator.MATERIAL; // or use DEFAULT
// generate random color
int color = generator.getColor(getItem(position));
TextDrawable drawable = TextDrawable.builder().buildRound(firstLetter,//radius in px color);
我的 XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<ImageView
android:id="@+id/image_view"
android:src="@drawable/ic_home_black_24dp"
android:layout_width="40dp"
android:layout_height="40dp" />
<TextView
android:id="@+id/text"
android:paddingLeft="20sp"
android:textSize="22sp"
android:fontFamily="sans-serif"
android:textColor="@color/darkcolor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="John" />
</LinearLayout>
最佳答案
使用 substring() 代替 chaAt()
String firstTwoChars = getItem(position).subString(0,2);
关于java - 如何在 Textdrawable 库中添加前两个字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56291279/
我是一名优秀的程序员,十分优秀!