How do I create a customized search-box for my application? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How do I create a customized search-box for my application? without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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

Answer

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
    }
    ...
}
We are here to answer your question about How do I create a customized search-box for my application? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji