2016-08-05 113 views
-2

我在我的應用程序中有幾個按鈕,我試圖對它們進行設計。自定義Android按鈕/ textview下劃線

這個想法是默認的狀態是純文本,下行狀態是下劃線的。下劃線應該與文字顏色不同,更粗,更圓,文字更長。我一直在試圖用Paint實現這一點,但沒有成功。

謝謝。這種類型的

+0

到目前爲止,您嘗試了什麼?請告訴我們你的努力,因爲[所以]不是軟件寫作服務。您應該首先閱讀[問]並在每個問題中提供[mcve]。 – xenteros

+0

我通過修改以下內容解決了這個問題:http://stackoverflow.com/questions/2394935/can-i-underline-text-in-an-android-layout/18735350#18735350 – Cynapsys

+0

然後,您可以將您的問題標記爲重複或刪除它。 – xenteros

回答

0

製作繪製,並將其添加爲ButtonTextView 一條線的繪製如下背景: -

<?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> 
+0

謝謝阿迪蒂。我將如何將筆畫的末端四捨五入並使用此方法控制文本的垂直距離。 – Cynapsys

0

這是壞主意,但...

您應該使用的顏色在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)); 
        } 
      } 
     });