How to add vertical lines to the left of my text?
I am showing a blockquote html in a TextView dynamically.
Asked
Active
Viewed 811 times
3

Phantômaxx
- 37,901
- 21
- 84
- 115
-
You could also use a **compound drawable** (`drawableLeft`, in this case), and save on an extra View. – Phantômaxx Aug 11 '16 at 12:33
-
can you explain more ? – Aug 11 '16 at 12:33
-
Please google for `android textview compound drawable` – Phantômaxx Aug 11 '16 at 13:04
4 Answers
1
Place on left of your textView
and use your desired dimensions and color.
<View
android:layout_width="2dp"
android:layout_height="100dp"
android:background="@color/colorPrimaryDark"></View>

Sohail Zahid
- 8,099
- 2
- 25
- 41
1
use
<View android:id="@+id/view"
android:layout_height="match_parent"
android:layout_width="1dp"
android:background="#000000" />
use webview for Html text
WebView webview = (WebView)this.findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadDataWithBaseURL("", data, "text/html", "UTF-8", "");
here is the code you want
String a = "You can ";
String b = "change" ;
String c = "like this" ;
String d = "if want to make it bold";
String sourceString = a + " " + "<b>" + b + "</b>" + " " + c + " " + "<b>" + d + "</b>";
textView.setText(Html.fromHtml(sourceString));
it will look like
You can change like this if want to make it bold

Anurag Shrivastava
- 650
- 7
- 25
-
-
-
@BincyBaby You can add a `textview` and set text as `.setText(Html.fromHtml("Your html string"))` – hrskrs Aug 11 '16 at 13:04
-
1
You can use View
:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:orientation="horizontal">
<View
android:layout_gravity="right"
android:background="#000000"
android:layout_width="2dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_height="match_parent" />
<TextView
android:text="balblalblablalblablalblalb"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
It will look like:
For showing Html
you can do as following:
yourTextView.setText(Html.fromHtml("your html string"));

hrskrs
- 4,447
- 5
- 38
- 52
-
-
You can create `TextView` dynamically like: `TextView t = new TextView(context);` than set `LayoutParams` based on your needs – hrskrs Aug 11 '16 at 12:38
0
Step 1: Add a Linear layout in a layout.
<LinearLayout
android:id="@+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="10dp">
</LinearLayout>
step2:In Activity , create TextView and a View dynamically add to linear layout
LinearLayout mylayout = (LinearLayout) findViewById(R.id.linear_layout);
TextView text = new TextView(this);
text.setText("Testing");
View view = new View(this);
view.setBackgroundColor(getResources().getColor(R.color.black));
view.setLayoutParams(new LinearLayout.LayoutParams(5, LinearLayout.LayoutParams.MATCH_PARENT));
mylayout.addView(view,0);
mylayout.addView(text,1);
Hope it helps!

Jenifer B
- 81
- 1
- 1
- 5