我怎样才能制作这样的 textview 节目。文本左侧的大蓝点

How can I make a textview show like this. A big blue dot to the left of text

我正在尝试在文本左侧添加项目符号或蓝点。我试过 textview.settext("\u2022 my text") 但是项目符号是黑色的,并且与其他文本的大小相比较小。 是否可以在文本左侧插入一个字符,我可以更改该字符的 color/size?我还可以创建一个自定义可绘制对象,它是蓝色的 "oval" 形状,但是如何将其插入到 "my text" 的左侧,以便效果如下所示。

SpannableString 没有按预期工作。这就是我所做的。

SpannableStringBuilder builder = new SpannableStringBuilder(" In the tumultuous business of cutting-in and attending.");
Drawable d = getResources().getDrawable(R.drawable.unread_dot_shape);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); // <---- Very important otherwise your image won't appear
ImageSpan myImage = new ImageSpan(d);

builder.setSpan(myImage, 0, 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
subjView.setText(builder, TextView.BufferType.SPANNABLE);

unread_dot_shape.xml 看起来像这样

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="@color/my_color_blue" />
    <corners
        android:radius="5dp" />
    <size
        android:width="5dp"
        android:height="5dp" />
</shape>

结果是这样的。

我希望圆点按照原始屏幕截图垂直对齐。

Is it possible to insert a character to the left of text

你在问题的代码片段中这样做了。

I can change color/size of that character?

欢迎您使用 SpannableString 而不是常规字符串将该字符包装在 ForegroundColorSpanRelativeSizeSpan 等中。

或者,使用 BulletSpan 并跳过字符,但我认为您无法控制项目符号的大小。

I can also create a custom drawable which is a "oval" shape of blue color but how can I insert that to the left of "my text" so that the effect is as below.

要么使用 ImageSpan 要么找到一个库,它允许您将文本环绕在 TextView 中的图像周围(我很确定有一个,虽然我不会来快速搜索)。

您可以通过在 TextView 中使用 Drawable 来实现此目的。

蓝点:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">

<solid android:color="@color/your_color" />
<size android:height="16dp" android:width="16dp"/> // Here you can set the size of the dot

然后,在您的布局中 xml:

           <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/your_dot"
            android:text="Your Text"
            />

您可以尝试使用 SpannableString

像这样:

  SpannableString spannableString = new SpannableString("string");
  ImageSpan imageSpan = new ImageSpan(context, R.drawable.blue_dot);
  spannableString.setSpan(imageSpan, 0, 1, 0);
  textView.setText(spannableString);