Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在文本左侧添加垂直线?_Android_Html_Textview_Blockquote - Fatal编程技术网

Android 如何在文本左侧添加垂直线?

Android 如何在文本左侧添加垂直线?,android,html,textview,blockquote,Android,Html,Textview,Blockquote,如何在文本左侧添加垂直线? 我在文本视图中动态显示一个blockquote html 放置在文本视图的左侧,并使用所需的尺寸和颜色 <View android:layout_width="2dp" android:layout_height="100dp" android:background="@color/colorPrimaryDark"></View> 使用 这是你想要的代码 String

如何在文本左侧添加垂直线?
我在文本视图中动态显示一个blockquote html


放置在
文本视图的左侧,并使用所需的尺寸和颜色

     <View
        android:layout_width="2dp"
        android:layout_height="100dp"
        android:background="@color/colorPrimaryDark"></View>

使用

这是你想要的代码

      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));
String a=“您可以”;
字符串b=“更改”;
String c=“像这样”;
String d=“如果要加粗”;
String sourceString=a+++++b+++c+++++d++;
setText(Html.fromHtml(sourceString));
看起来像


您可以这样更改,如果您想将其加粗

您可以使用查看

<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>
步骤1:在布局中添加线性布局。
步骤2:在“活动”中,创建文本视图,并将视图动态添加到线性布局
LinearLayout mylayout=(LinearLayout)findViewById(R.id.linear\U布局);
TextView text=新的TextView(此);
text.setText(“测试”);
视图=新视图(此);
view.setBackgroundColor(getResources().getColor(R.color.black));
view.setLayoutParams(新的LinearLayout.LayoutParams(5,LinearLayout.LayoutParams.MATCH_父项));
mylayout.addView(视图,0);
mylayout.addView(文本,1);

希望有帮助

要动态创建文本视图,请从html设置文本。您可以动态创建
textview
,如:
textview t=new textview(context)
然后根据需要设置
布局参数
要动态创建文本视图,请从html设置文本。要动态创建文本视图,请从html设置文本。无需使用webview@BincyBaby您可以添加一个
textview
并将文本设置为
.setText(Html.fromHtml(“您的Html字符串”)
您到底想做什么。请解释@BincyBabyYou也可以使用复合可绘图(
drawableLeft
,在这种情况下),并保存在额外的视图上。您能解释更多吗?请谷歌搜索
android textview复合可绘图
      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));
<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>
yourTextView.setText(Html.fromHtml("your html string"));
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);