如何在我的文本左侧添加垂直线?
我在 TextView 中动态显示块引用 html。
4 回答
1
放置在您的左侧textView
并使用您想要的尺寸和颜色。
<View
android:layout_width="2dp"
android:layout_height="100dp"
android:background="@color/colorPrimaryDark"></View>
于 2016-08-11T12:22:44.490 回答
1
利用
<View android:id="@+id/view"
android:layout_height="match_parent"
android:layout_width="1dp"
android:background="#000000" />
对 Html 文本使用 webview
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));
它看起来像
如果想让它变粗,你可以这样改变
于 2016-08-11T12:23:02.177 回答
1
您可以使用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"));
于 2016-08-11T12:26:13.620 回答
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);
希望能帮助到你!
于 2016-08-11T13:28:11.153 回答