0

editext image如何添加彎曲下劃線到Edittext或Searchview?

我想創建類似於搜索查看如果可能的話或一個EditText,我相信這是在全息主題,但我的項目主題是Appcompact,日Thnx。

+0

嘗試使用自定義背景使用XML drawable的edittext – Sodiq

+0

謝謝,但那是我的問題我不知道如何完全做到這一點。 – rawa300

+0

請參閱[這裏](http://stackoverflow.com/questions/3646415/how-to-create-edittext-with-rounded-corners)關於如何使圓角的editText –

回答

1

在佈局文件

<EditText 
    android:id="@+id/editText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:hint="EditText" 
    android:padding="8dp" 
    /> 

edit_text_drawable.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <corners android:radius="16dp"/> 
    <solid android:color="@android:color/transparent"/> 
    <stroke 
     android:color="@color/colorBlue" 
     android:width="2dp" /> 
</shape> 

此繪製將用作EditText上的背景。 標籤筆劃爲此形狀設置輪廓 - 此處設置的輪廓寬度爲&顏色。

在你的代碼

EditText editText = (EditText) findViewById(R.id.editText); 

ClipDrawable clipDrawable = new ClipDrawable 
       (getResources().getDrawable(R.drawable.edit_text_drawable), 
        Gravity.BOTTOM, ClipDrawable.VERTICAL); 
clipDrawable.setLevel(2000); 

editText.setBackground(clipDrawable); 

這裏ClipDrawable 「作物」 底色繪製。 ClipDrawable documentation

+0

thnx爲雁 – rawa300