how to add border to a text in textview android

前端 未结 4 1088
一整个雨季
一整个雨季 2020-12-31 04:32

In Android, how can you add a border around a text? I want a border around the text in TextView not around the TextView.Is there any way to do it in? If so, please

相关标签:
4条回答
  • 2020-12-31 05:01

    You can create style for this..

    Here is sample style for borderline on text..

    Style.xml

    <resources xmlns:android="http://schemas.android.com/apk/res/android">
     <style name="shadoweffect">
            <item name="android:paddingLeft">4px</item>
            <item name="android:paddingBottom">4px</item>
            <item name="android:textColor">#FFFFFF</item>
            <item name="android:textSize">25sp</item>
            <item name="android:shadowColor">#000000</item>
            <item name="android:shadowDx">0</item>
            <item name="android:shadowDy">0</item>
            <item name="android:shadowRadius">3</item>
        </style>
    
    </resources>
    

    Apply style on your TextView

     <TextView
          style="@style/shadoweffect"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="your_text" />
    
    0 讨论(0)
  • 2020-12-31 05:03

    Android does not have such feature originally. A few months ago, I had to develop a similar feature, and I used some trick. In that case I used the shadow attribute. In your case on TextView.onDraw() call super() two times. Set the typeface to bold and set the color to border color and call one time, and set normal and call second time. That will work.

    0 讨论(0)
  • 2020-12-31 05:09

    You can use any TextEditors to create a border for ur text and you can add to the code

    0 讨论(0)
  • 2020-12-31 05:11

    Try this..

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello_world"
        android:textColor="#f8f36a"
        android:textSize="65sp"
        android:shadowColor="#ff0000" 
        android:shadowRadius="2"/>
    

    and the result is

    result

    You can create custom border for text like this..Here is a sample application.

    enter image description here

    0 讨论(0)
提交回复
热议问题