1

I have one header layout looks like this.enter image description here

Now on on the very next of the right side of the button i want to add this image enter image description here and try to used the Collapsible SearchView without using action bar means i want to apply the same effect of action bar search view on my layout header. enter image description here

More over I also want to remove the Name and icon of the app which comes above the header.

Any Idea how to achieve this??

your help/suggestions will be appreciated...

Thanks in advance...

EDIT ::

what i have tried so far is ...

this is the my header.xml

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" >

    <RelativeLayout
        android:id="@+id/layout_header"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/topbar"
        android:paddingLeft="10dp"
        android:paddingRight="10dp" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/btnPrevious"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/previous" />
        </LinearLayout>

        <TextView
            android:id="@+id/tv_headerText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:layout_gravity="center|center_vertical|fill_horizontal"
            android:text="Home"
            android:textColor="#FFFFFF"
            android:textSize="20dp"
            android:textStyle="bold" />

        <Button
            android:id="@+id/btnLogout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:background="@drawable/logout" />

        <ImageButton
            android:id="@+id/imgSearch"
            style="@style/Widget.Sherlock.ActionButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@+id/btnLogout"
            android:src="@drawable/ic_search_inverse"
            android:title="Search" />

        <com.actionbarsherlock.widget.SearchView
            android:id="@+id/searchView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/tv_headerText"
            android:layout_marginTop="10dp"
            android:layout_toLeftOf="@+id/imgSearch"
            android:background="@drawable/ic_search_inverse"
            android:visibility="gone" />
    </RelativeLayout>

</merge>

search_menu.xml

<item
    android:id="@+id/action_search"
    android:actionViewClass="android.widget.SearchView"
    android:icon="@android:drawable/ic_menu_search"
    android:showAsAction="always"
    android:title="Search"/>

layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    android:orientation="vertical" >

    <!-- header Part -->

    <include layout="@layout/header" />

    <!-- header Part is over. -->

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="10dp" >

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="None"
            android:textColor="@color/black"
            android:textSize="25dp"
            android:textStyle="bold"
            android:visibility="gone" />

        <ListView
            android:id="@+id/list"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_below="@+id/et_productSearch"
            android:cacheColorHint="#00000000"
            android:scrollbars="none" >
        </ListView>
    </RelativeLayout>

</LinearLayout>

in My Home.java

ImageView imgSearch;
SearchView searchView;

imgSearch=(ImageView)findViewById(R.id.imgSearch);
searchView = ((SearchView)findViewById(R.id.searchView));


searchView.setOnCloseListener(new SearchView.OnCloseListener() {
   @Override
   public boolean onClose() {
        searchView.setVisibility(View.INVISIBLE);
        return false;
        }
   });

my OnOptionItemSelected ::

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {

        case R.id.action_search:
            if (searchView.getVisibility() == View.VISIBLE) {
                searchView.setIconified(true);
                searchView.setVisibility(View.INVISIBLE);
            } else {
                //searchView.setMaxWidth(searchView,getWidth() - imgSearch.getWidth());
                searchView.setVisibility(View.VISIBLE);
                searchView.setIconified(false);
            }
            break;
        }
        return true;
    }
AndroidLearner
  • 4,500
  • 4
  • 31
  • 62

1 Answers1

0

this question was answered in SO already:

Android ActionBar: collapsible SearchView with action button

take look.

Community
  • 1
  • 1
בועז יערי
  • 445
  • 1
  • 5
  • 14
  • Thank you very much for your quick response.I have did the same as per the above link said..But m bit confuesd that what to do onClick of the imgSearch(Image Search)?? – AndroidLearner Oct 22 '13 at 07:35
  • @AndroidLearner - maybe you should take a look here: http://developer.android.com/guide/topics/search/search-dialog.html seems like you don't really understand how the SearchView works.. – בועז יערי Oct 22 '13 at 07:46
  • See my updated Question which gives you the more clear picture so you can suggest me something better than the links. My Question is pretty much clear that what piece of code/logic i need to write onClick of the imageview so i can get the effect of the collapsible action bar searchview.? – AndroidLearner Oct 22 '13 at 08:45