17

I want to increase space between text and it's underline. I can change line height but I don't change height between text and it's underline.How can I do this ?

private static final String FONTH_PATH = "fonts/Brandon_bld.otf";

...

selectTextView = (TextView) findViewById(R.id.selectTextView);
selectTextView.setTypeface(font);

SpannableString content = new SpannableString(getResources().getString(R.string.select_your_prove_type));
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
selectTextView.setText(content);

...

and xml file

<TextView
android:id="@+id/selectTextView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="536"
android:gravity="left"
android:lineSpacingMultiplier="0.8"
android:text="@string/select_your_prove_type"
android:textColor="@color/Blue"
android:textSize="@dimen/select_size" />
Maveňツ
  • 1
  • 12
  • 50
  • 89
buraktemzc
  • 390
  • 1
  • 6
  • 19
  • I don't know the answer, maybe linespacingextra attribute should do it but why is your weight attribute has value 536 `android:layout_weight="536"`? – Rahul Gupta Sep 23 '14 at 12:19
  • lineSpacingExtra does not work for this issue. I split the screen according to Iphone psd. Height is 1136 px in this psd and my root layout weightSum is also 1136. – buraktemzc Sep 23 '14 at 22:24

4 Answers4

11

Just use the

paddingBottom

as follows

         <android.support.design.widget.TextInputLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/fragment_activity_edit_desc"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="16dp"
                android:hint="Description"
                android:textSize="34sp"
                tools:text="Secret Death Ray Design"/>


        </android.support.design.widget.TextInputLayout>
Uzair
  • 1,529
  • 14
  • 17
2

Okay here's a more complete answer:

In your styles.xml, add a style:

<style name="MyTour.HeadingText">
    <item name="android:background">@drawable/tour_header_line_layerlist</item>
</style>

Now create a tour_header_line_layerlist.xml file with content:

<layer-list
    xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="20dp" android:drawable="@drawable/tour_header_line"/>
</layer-list>

The above will set a margin top of 20dp for the line (extract it out to dimen.xml for completeness)

Now create the corresponding tour_header_line.xml:

<shape android:shape="line"
   xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
        android:width="1dp"
        android:color="@color/tour_subheading_color" />

Now reference the style in your control:

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="@string/tour_1_heading_text"
            android:id="@+id/heading_text" android:layout_gravity="center_horizontal"
            style="@style/MyTour.HeadingText" //notice this
            android:layout_marginTop="@dimen/margin_large"/>

Let me know if you have other questions!

Hugo Gresse
  • 17,195
  • 9
  • 77
  • 119
Tommy Chan
  • 622
  • 7
  • 14
  • This is working great with android:top="20dp", Why it's not working when we change top value? – Dilip Jun 17 '15 at 12:18
  • Works if you are just underlining an entire TextView, but won't work on individual lines or sections of lines and doesn't address OP's UnderlineSpan issue – Tom Feb 10 '22 at 22:38
2

Add these line in EditText

<EditText
   ...
   android:includeFontPadding="true"
   android:paddingBottom="20dp" />
Edric
  • 24,639
  • 13
  • 81
  • 91
-1

You can add the custom underline with a drawable file (in my case I've created a shadow) and set this custom underline with

android:background="@drawable/shadow_file.xml"

After that with adding padding to your EditText you can add more space between the line and the text.

android:paddingBottom="@dimen/underline_space"

and define this dimension on your dimens.xml file.

That works for me, and I hope for you too :)

jgarciabt
  • 559
  • 1
  • 5
  • 19
  • Thank you for sharing your answer but I couldn't understand. Did you create a custom edittext ? @jgarciabt – buraktemzc Feb 13 '15 at 12:01
  • Sorry for my short explanation. I've got a default EditText but with a custom underline. You can add the custom underline with a drawable file (in my case I've created a shadow) and with android:background="@drawable/shadow_file.xml" set this custom underline. After that with the padding you can add more space between the line and the text. – jgarciabt Feb 13 '15 at 14:45
  • 1
    can you please share shadow_file.xml or explain how to add it? – Dhasneem Mar 11 '15 at 13:14
  • if you share `shadow_file.xml`, it would be more clear. – Sulav Timsina Sep 23 '20 at 06:28