我有一个标题布局看起来像这样。
现在在按钮右侧的下一个,我想添加此图像并尝试使用 Collapsible SearchView 而不使用操作栏,这意味着我想在我的布局标题上应用与操作栏搜索视图相同的效果。
此外,我还想删除标题上方的应用程序的名称和图标。
任何想法如何实现这一目标?
您的帮助/建议将不胜感激...
提前致谢...
编辑 ::
到目前为止我所尝试的是......
这是我的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"/>
布局.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>
在我的家.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;
}
});
我的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;
}