How do I add a bullet symbol in TextView?

后端 未结 9 1122
感动是毒
感动是毒 2020-11-30 17:27

I have a TextView and I want to add a bullet symbol in my text through XML. Is it possible?

相关标签:
9条回答
  • 2020-11-30 18:19

    You may try BulletSpan as described in Android docs.

    SpannableString string = new SpannableString("Text with\nBullet point");
    string.setSpan(new BulletSpan(40, color, 20), 10, 22, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    

    0 讨论(0)
  • 2020-11-30 18:20

    Another best way to add bullet in any text view is stated below two steps:

    First, create a drawable

    <?xml version="1.0" encoding="utf-8"?>
    <shape
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="oval">
    
        <!--set color of the bullet-->
       <solid 
           android:color="#666666"/> //set color of bullet
    
        <!--set size of the bullet-->
       <size 
           android:width="120dp"
            android:height="120dp"/>
    </shape>
    

    Then add this drawable in textview and set its pedding by using below properties

    android:drawableStart="@drawable/bullet"
    android:drawablePadding="10dp"
    
    0 讨论(0)
  • 2020-11-30 18:21

    Since android doesnt support <ol>, <ul> or <li> html elements, I had to do it like this

    <string name="names"><![CDATA[<p><h2>List of Names:</h2></p><p>&#8226;name1<br />&#8226;name2<br /></p>]]></string>
    

    if you want to maintain custom space then use </pre> tag

    0 讨论(0)
提交回复
热议问题