2017-10-29 110 views
-1

我想要一個帶有不同外觀的textview(僅下劃線是確切的)有人可以幫我怎麼做到這一點。我在做xamarin android。動態帶下劃線的字母

underlined letters

回答

2

您可以使用shape劃清界限。

1.shape_line.xml

,你可以改變android:widthandroid:height

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <solid android:color="@android:color/white" /> 
    <padding android:top="10dp" /> 
    <size 
     android:width="60dp" 
     android:height="10dp" /> 
</shape> 

2.使用方法如下。

editText = (EditText) findViewById(R.id.et); 
editText.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, R.drawable.shape_line); 

3,如果您使用EditText,你應該設置android:background="@null"。否則它會在底部的顏色。

<EditText 
    android:id="@+id/et" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:background="@null" 
    android:gravity="center" 
    android:text="N" 
    android:textColor="@android:color/white" /> 

輸出

enter image description here

+0

我不能嘗試,但現在我肯定會嘗試。謝謝! – xDarC

+0

祝你好運。 – KeLiuyue

+0

它工作。謝謝! – xDarC