How to increase space between text and it's underline in TextView Android?

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" />

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>

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!


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 :)

链接地址: http://www.djcxy.com/p/81740.html

上一篇: 在Symfony 2中创建一个表单网格

下一篇: 如何增加TextView Android中的文本和下划线之间的空间?