Reputation: 1774
I am looking for a solution to a problem with quoting part of a text in a TextView. There is a long text and some parts need to be quoted/highlighted. I have made something in HTML (Html.fromHtml(String)) but without this red vertical line. Do you have any idea how to add it ? As far as I know, CSS styling is not possible in TextView.
Upvotes: 1
Views: 672
Reputation: 5402
This is a really old question but in case anybody else stumbles upon this, QuoteSpan does exactly what you want:
val quoted = SpannableStringBuilder("here is some quoted text\n")
quoted.setSpan(QuoteSpan(myColor), 0, quoted.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
val entireString = SpannableStringBuilder()
entireString.append("before quote\n")
entireString.append(quoted)
entireString.append("after quote")
Upvotes: 0
Reputation: 436
Do not use two view for it. You just create a xml background file as follows
bg_quote_text.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/colorPrimary" />
<size android:width="2dp" />
</shape>
</item>
<item android:left="2dp">
<shape android:shape="rectangle">
<solid android:color="@android:color/white" />
</shape>
</item>
</layer-list>
android:width="2dp" and android:left="2dp" are vertical line width. Finally you set bg_quote_text to background of TextView also do not forget to padding attribute.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_quote_text"
android:paddingLeft="8dp"
android:text="Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum "
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/iv_artist" />
Its done.
Upvotes: 1
Reputation: 8149
Webview with custom line view.
TextView with custom line view.
TextView
Webview
wrap_content
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/base"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="horizontal">
<View
android:layout_width="3dp"
android:layout_height="wrap_content"
android:background="#B1233A"
android:layout_toStartOf="@+id/webView"
android:layout_alignTop="@+id/webView"
android:layout_alignBottom="@+id/webView"
android:layout_marginRight="10dp" />
<WebView
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:id="@+id/webView"></WebView>
<!--<TextView-->
<!--android:layout_width="200dp"-->
<!--android:layout_height="wrap_content"-->
<!--android:text="My textt from web \nand in multiple \nLines"-->
<!--android:layout_centerHorizontal="true"-->
<!--android:layout_centerVertical="true"-->
<!--android:id="@+id/webView"></TextView>-->
</RelativeLayout>
Upvotes: 3
Reputation: 220
try this:
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="#FF0000FF" />
Upvotes: 0