How do I add a bullet symbol in TextView?
You have to use the right character encoding to accomplish this effect. You could try with •
Update
Just to clarify: use `setText("\u2022 Bullet");` to add the bullet programmatically. `0x2022 = 8226`How to add bullets to text view in android
These dots are represented by \u2022
char
How to add bulleted list to android application?
Tough to do as ul/li/ol are not supported. Fortunately you can use this as syntactic sugar:
• foo<br/>
• bar<br/>
• baz<br/>
•
is the html entity for a list bullet
more choices are here http://www.elizabethcastro.com/html/extras/entities.html
more about which tags are supported provided by Mark Murphy (@CommonsWare)
http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html
Load that up with Html.fromHtml
((TextView)findViewById(R.id.my_text_view)).setText(Html.fromHtml(myHtmlString));
Android: how to give bulletpoints, line break to text in textview
Thank you all...i finally ended up doing this
String nodata="hi how are you<br/>•welcome to stackoverflow"
TextView nodata= ((TextView) findViewById(R.id.nodata));
nodata.setText(Html.fromHtml(nodatafound));
and for justify left i did change in my layout file android:layout_gravity=center|left
i hope there is a betterway doing this.
Add Bullets with proper formatting in Android
Would You be satisfied of this example?
public class MainActivity extends AppCompatActivity {
private TextView tvProdDesc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvProdDesc = (TextView) findViewById(R.id.text1);
String longDescription = "Enhanced bass performance.\n" +
"Lightweight headband enhances comfort and adds durability\n" +
"Easy to adjust headband ensures optimum fit and comfort\n" +
"2 metre-long cable";
String arr[] = longDescription.split("\n");
int bulletGap = (int) dp(10);
SpannableStringBuilder ssb = new SpannableStringBuilder();
for (int i = 0; i < arr.length; i++) {
String line = arr[i];
SpannableString ss = new SpannableString(line);
ss.setSpan(new BulletSpan(bulletGap), 0, line.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ssb.append(ss);
//avoid last "\n"
if(i+1<arr.length)
ssb.append("\n");
}
tvProdDesc.setText(ssb);
}
private float dp(int dp) {
return getResources().getDisplayMetrics().density * dp;
}
}
Result:
Add bullet points between textview in horizontal listview
Use drawableLeft
property for adding bullets in textview
as for xml
android:drawableLeft="your_file"
also in your view first image has no bullet then in code put check that
if(position == 0)
listTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
Indent bullet list in TextView
I'm suprised that there seems to be noone with this problem. I mean, bullet list can't be that uncommon in about-dialogs, FAQ etc and a bullet doesn't have to contain too much text to span more than one row and run into this problem.
Anyway, I got to solve it like this for now:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="@+id/ScrollViewTipsLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TipsLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableLayout
android:layout_height="wrap_content"
android:id="@+id/TableLayout01"
android:layout_width="wrap_content"
>
<TableRow>
<TextView android:id="@+id/tvIngress"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@+string/tv_picking_content_ingress"
android:layout_span="2"
android:singleLine="false"
android:layout_weight="1"
/>
</TableRow>
<TableRow>
<TextView android:id="@+id/tvCleaningDot1"
android:layout_height="wrap_content"
android:text="•"
android:singleLine="false"
/>
<TextView android:id="@+id/tvCleaningFirst"
android:layout_height="wrap_content"
android:text="@+string/tv_picking_content_first"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="left"
android:singleLine="false"
/>
</TableRow>
<TextView android:id="@+id/tvCleaningDot2"
android:layout_height="wrap_content"
android:text="•"
android:singleLine="false"
/>
<TextView android:id="@+id/tvCleaningSecond"
android:layout_height="wrap_content"
android:text="@+string/tv_picking_content_second"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="left"
android:singleLine="false"
/>
</TableRow>
</TableLayout>
</RelativeLayout>
I use it to present static text in a bullet list so I don't bother to create the bullet + text dynamically in code. If anyone have any suggestion how to accomplish the same thing in a better way, please enlight me.
Btw, if going with the solution suggested in second link above:
android:text="<ol><li>item 1\n</li><li>item 2\n</li></ol>
The second, third etc. row in a bullet that span over more than one row won't get same indention as first line, which is quite ugly.
Android having paragraph and numbering/bullets on textview
If your text is static then you can extend TextView
to automatically prepend a BulletSpan
before your android:text
:
layout.xml
<BulletTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Orange" />
<BulletTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Banana" />
BulletTextView.java
/**
* {@link TextView} that automatically adds bullet point to text if set in layout
*/
public class BulletTextView extends TextView {
public BulletTextView(Context context) {
super(context);
addBullet();
}
public BulletTextView(Context context, AttributeSet attrs) {
super(context, attrs);
addBullet();
}
public BulletTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
addBullet();
}
public BulletTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
addBullet();
}
private void addBullet() {
CharSequence text = getText();
if (TextUtils.isEmpty(text)) {
return;
}
SpannableString spannable = new SpannableString(text);
spannable.setSpan(new BulletSpan(16), 0, text.length(), 0);
setText(spannable);
}
}
You can further customize this by adding custom attribute for indentation.
Related Topics
How to Set Text Color of a Textview Programmatically
Read Logs from All Apps on Android from Within an App for Android 4.2+
How to Read All The Coming Notifications in Android
How to Put Recyclerview Inside Nestedscrollview
How to Tell If My Textview Has Been Ellipsized
Timepicker Dialog from Clicking Edittext
Using Android Google Maps V2 with Custom View or Imageview
How to Create a Release Android Library Package (Aar) in Android Studio (Not Debug)
How to Create Android Project with Gradle from Command Line
Android Browser Ignores Responsive Web Design
Is There a Workaround for The Android Browser Bug with CSS-Position and Clickable Areas
Android/Java: How to Delay Return in a Method
How to Style Appcompat-V7 Toolbar Like Theme.Appcompat.Light.Darkactionbar
CSS Overflow and Absolute Positioning Issue on Android Browser
How to Override a Module/Dependency in a Unit Test with Dagger 2.0
Android: Textcolor of Disabled Button in Selector Not Showing
Firestorepagingadapter Not Receiving Realtime Updates
Scaling a Phonegap App for Different Android Screen Sizes/Densities