- TextView 添加下划线
// 设置 TextView 的 Paint 属性-下划线
textView.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
- 设置 TextView 的文本内容预览,但在项目运行中不显示
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="文本格式预览"
/>
<!--android:text="文本格式预览"-->
3.设置 Textview 行高和字间距
android:textScaleX
设置的值为 float 类型。
android:lineSpacingExtra
设置行间距,如 2dp。
android:lineSpacingMultiplier
设置行间距的倍数。
4.在代码中动态设置 TextView 的 drawable(left, top, right, bottom)
// 获取图片资源
Drawable drawableLeft = getResources().getDrawable(
R.drawable.ic_launcher);
// 设置图片位置
textDrawable.setCompoundDrawablesWithIntrinsicBounds(drawableLeft,
null, null, null);
// 设置图片与文字间距
textDrawable.setCompoundDrawablePadding(4);