Как добавить вертикальные линии слева от моего текста?
Я показываю blockquote html в TextView динамически.Как добавить вертикальные линии слева от моего текста?
ответ
Место слева от вашего textView
и используйте требуемые размеры и цвет.
<View
android:layout_width="2dp"
android:layout_height="100dp"
android:background="@color/colorPrimaryDark"></View>
хотите создать текстовое представление динамически, установить текст из html. –
использование
<View android:id="@+id/view"
android:layout_height="match_parent"
android:layout_width="1dp"
android:background="#000000" />
использование WebView для Html текста
WebView webview = (WebView)this.findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadDataWithBaseURL("", data, "text/html", "UTF-8", "");
вот код, который вы хотите
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));
это будет выглядеть
Вы можете изменить как этот , если хотите, чтобы сделать его полужирным
хотите создать текстовое представление динамически, установить текст из html. –
проверка отредактированный ответ @BincyBaby –
без использования WebView –
Вы можете использовать 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>
Это будет выглядеть так:
За показ Html
вы можете сделать следующее:
yourTextView.setText(Html.fromHtml("your html string"));
хотите создать текстовое представление динамически, установить текст из html. –
Вы можете создать 'TextView' динамически, как:' TextView t = новый TextView (контекст); 'чем установить' LayoutParams' на основе ваших потребностей – hrskrs
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);
Надеюсь, это поможет!
Вы также можете использовать ** составную ** ('drawableLeft', в данном случае) ** и сохранить дополнительный просмотр. –
вы можете объяснить больше? –
Пожалуйста, google для 'android textview compound drawable' –