android studio怎么给textview添加分隔线
时间: 2023-10-18 08:18:46 浏览: 65
你可以使用以下代码,给TextView添加分隔线:
```
textView.setPaintFlags(textView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
```
这会使用一个删除线来绘制TextView的文本,从而模拟出分隔线的效果。
相关问题
android studio怎么给textview添加下划线
对于您的问题,可以使用以下代码来给 TextView 添加下划线:
```
TextView textView = findViewById(R.id.textView);
textView.setPaintFlags(textView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
```
这将为 TextView 添加下划线效果。如有其他问题,请随时提出。
Android studio 用控件TextView 添加图片
你可以使用TextView的`setCompoundDrawables()`方法来在TextView中添加图片。这个方法需要四个参数,分别是左侧、顶部、右侧和底部的Drawable对象。
以下是一个示例代码,演示如何在TextView中添加左侧的图片:
```java
TextView textView = findViewById(R.id.textview);
Drawable drawable = getResources().getDrawable(R.drawable.ic_launcher);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
textView.setCompoundDrawables(drawable, null, null, null);
```
在这个示例中,我们首先获取了一个TextView对象,并且使用`getResources()`方法获取了一个Drawable对象。接下来,我们使用`setBounds()`方法来设置Drawable对象的大小和位置。最后,我们使用`setCompoundDrawables()`方法将Drawable对象与TextView相关联,这样就可以在TextView的左侧添加图片了。
需要注意的是,如果你想在TextView中添加多个图片,你需要使用`setCompoundDrawablesWithIntrinsicBounds()`方法,并传递四个参数,分别是左侧、顶部、右侧和底部的Drawable资源ID。