-2

I have several buttons in my application and I am trying to style them.

The idea is the default state is plain text and the down state is underlined. The underline should be a different color to the text, thicker, rounded and the length of the word. I have been trying to achieve this with Paint but without success.

Thank you.

Cynapsys
  • 7
  • 1
  • 5
  • What have you tried so far? Please show us your effort as [so] isn't software writing service. You should read [ask] first and provide [mcve] in each question. – xenteros Aug 05 '16 at 11:05
  • I resolved this by modifying the following: http://stackoverflow.com/questions/2394935/can-i-underline-text-in-an-android-layout/18735350#18735350 – Cynapsys Aug 05 '16 at 12:07
  • You can then flag your question as a duplicate or delete it. – xenteros Aug 05 '16 at 12:09

2 Answers2

0

Make drawable of that type and add it as a background of Button or TextView A line drawable as below:-

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@android:color/transparent" /> <!--background color of box-->
        </shape>
    </item>

    <item
        android:top="-2dp"
        android:right="-2dp"
        android:left="-2dp"
        android:bottom="5dp">
        <shape>
            <solid android:color="@android:color/transparent" />
            <stroke
                android:width="3dp"
                android:color="@android:color/black" />  <!-- color of stroke -->
        </shape>
    </item>
</layer-list>
Aditi
  • 455
  • 4
  • 13
  • Thanks Aditi. How would I round the ends of the stroke and control the vertical distance from the text using this method. – Cynapsys Aug 05 '16 at 11:35
0

This is bad idea but...

You should use color selector for text and handle underlining in OnClickListener.

<string name="label_underlined"><u>This text has an underscore</u></string>
<string name="label_default">Default text</string>

button.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 v.setChecked(v.isChecked());
                 if (v.isChecked()){
                    button.setText(getString(R.string.label_underlined));
                 } else {
                     button.setText(getString(R.string.label_default));
                     }
             }
         });
Andrew F
  • 1,712
  • 2
  • 15
  • 24