1

editext image

I want to create a searchview if possible or an edittext similar to that, i beleive It's in holo theme but my project theme is Appcompact, thnx.

Maksim Ostrovidov
  • 10,720
  • 8
  • 42
  • 57
rawa300
  • 27
  • 1
  • 8

1 Answers1

1

in your layout file

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

This drawable will be used as EditText's background. Tag stroke makes outline for this shape - set outline width & color here.

in your code

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

Here ClipDrawable "crops" backround drawable. ClipDrawable documentation

Maksim Ostrovidov
  • 10,720
  • 8
  • 42
  • 57