How do you underline a text in Android XML?

前端 未结 10 950
不思量自难忘°
不思量自难忘° 2020-12-04 14:57

How do you underline a text in an XML file? I can\'t find an option in textStyle.

相关标签:
10条回答
  • 2020-12-04 15:46

    To complete Bhavin answer. For exemple, to add underline or redirection.

    ((TextView) findViewById(R.id.tv_cgu)).setText(Html.fromHtml(getString(R.string.upload_poi_CGU)));
    
    <string name="upload_poi_CGU"><![CDATA[ J\'accepte les <a href="">conditions générales</a>]]></string>
    

    and you can know compatible tag here : http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html

    0 讨论(0)
  • 2020-12-04 15:47

    You can use the markup below, but note that if you set the textAllCaps to true the underline effect would be removed.

    <resource>
        <string name="my_string_value">I am <u>underlined</u>.</string>
    </resources>
    


    Note

    Using textAllCaps with a string (login_change_settings) that contains markup; the markup will be dropped by the caps conversion

    The textAllCaps text transform will end up calling toString on the CharSequence, which has the net effect of removing any markup such as . This check looks for usages of strings containing markup that also specify textAllCaps=true.

    0 讨论(0)
  • 2020-12-04 15:47

    If you want to compare text String or the text will change dynamically then you can created a view in Constraint layout it will adjust according to text length like this

     <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    
        <TextView
            android:id="@+id/txt_Previous"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginEnd="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginBottom="8dp"
            android:gravity="center"
            android:text="Last Month Rankings"
            android:textColor="@color/colorBlue"
            android:textSize="15sp"
            android:textStyle="bold"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent" />
    
        <View
            android:layout_width="0dp"
            android:layout_height="0.7dp"
            android:background="@color/colorBlue"
            app:layout_constraintEnd_toEndOf="@+id/txt_Previous"
            app:layout_constraintStart_toStartOf="@+id/txt_Previous"
            app:layout_constraintBottom_toBottomOf="@id/txt_Previous"/>
    
    
    </android.support.constraint.ConstraintLayout>
    
    0 讨论(0)
  • 2020-12-04 15:48

    There are different ways to achieve underlined text in an Android TextView.

    1.<u>This is my underlined text</u> or

    I just want to underline <u>this</u> word
    

    2.You can do the same programmatically.

    `textView.setPaintFlags(textView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);`
    

    3.It can be done by creating a SpannableString and then setting it as the TextView text property

    SpannableString text = new SpannableString("Voglio sottolineare solo questa parola");
    text.setSpan(new UnderlineSpan(), 25, 6, 0);
    textView.setText(text);
    
    0 讨论(0)
提交回复
热议问题