【发布时间】:2016-04-29 10:29:29
【问题描述】:
我有一个带有回收器视图的 CollapsingToolbarLayout。在我的操作栏中,我有一个搜索菜单项。但是每当我单击搜索图标时,edittext 布局都不会出现。
我的 main_activity.xml 代码:-
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:id="@+id/activity_main_id"
tools:context="objectdistance.ankeshkjaisansaria.ram.sita.cameratag.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
android:fitsSystemWindows="true">
<ImageView
android:id="@+id/imagetoolbar"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
在我的 activity.java 中,搜索项是这样处理的:-
ActionBar action = getSupportActionBar(); //get the actionbar
action.setDisplayShowCustomEnabled(true); //enable it to display a
// custom view in the action bar.
action.setCustomView(R.layout.search_bar);//add the custom view
action.setDisplayShowTitleEnabled(false); //hide the title
但 search_bar 布局不仅仅出现。而且标题也没有隐藏。
在使用折叠布局时是否有任何不同的方式来处理菜单项中的搜索?
【问题讨论】:
-
也发布您的代码。
-
您是否在
menu.xml或任何自定义菜单XML中添加了Search View的项目? -
@jaydroider 我已经编辑了显示屏幕截图的问题。我得到了搜索图标和所有东西。唯一的问题是没有显示编辑文本。
-
是的,我已经检查了您的屏幕截图。您是否在
manifest中授予了所需的权限。 -
@jaydroider 哪个权限
标签: android android-actionbar menuitem android-menu android-collapsingtoolbarlayout