0

How can I make a customized search-box for my android application? Something like this, for example : enter image description here

Or if it's hard, is it possible to use the Android SearchManager in local app?

enter image description here

Kermia
  • 4,171
  • 13
  • 64
  • 105

3 Answers3

2

As bughi stated, use custom background 9-patch drawables for your widget. The second image consists of EditText and ImageButton placed next to each other. Use 9-patch drawable like this for EditText background drawable for EditText and 9-patch drawable like this for ImageButton background drawable for ImageButton. Sure use selector as android:background for widget states as normal, pressed and focused.

First image can be achieved also by using attribute android:drawableRight. Overriden onTouchEvent() method of your widget can look like this:

public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_UP && event.getX() >= getWidth() - getCompoundPaddingRight()) {
        // search drawable was touched
    }
    ...
}
biegleux
  • 13,179
  • 11
  • 45
  • 52
1

Just use your own images as background instead of the default ones.

For the EditText view i suggest looking into 9-patch for it to be able to resize smoothly on any screen.

bughi
  • 1,838
  • 1
  • 13
  • 24
1

For the background I think it's easier to use a drawable shape like this:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <corners android:radius="10dp" />

    <solid android:color="@android:color/white" />

    <padding 
        android:left="8dp"
        android:right="8dp"
        android:top="8dp"
        android:bottom="8dp" />

</shape>

The radius gives the background the rounded borders and can be easily adjusted, so is the size changing the padding.

Alejandro Casanova
  • 3,633
  • 4
  • 31
  • 46