Domanda

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

È stato utile?

Soluzione

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

Altri suggerimenti

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.

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top