在Android工具栏中的expandig searchview时将图标推开 [英] Push icons away when expandig searchview in android toolbar

查看:99
本文介绍了在Android工具栏中的expandig searchview时将图标推开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正面临这种特殊行为,我不知道如何解决..

I'm facing this particular behaviour and I don't know how to fix it..

在我的活动中,我具有以下工具栏:

In my activity I have this toolbar:

当您单击搜索图标时,它会展开并将另一个图标推到视图之外.

And when you click on the search icon it expands and pushes the other icon to out of the view.

我想知道如何将图标保持在右侧并减少搜索视图空间.

I want to know how could I keep the icon on the right and reduce the search view space.

这是我的菜单布局:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
    android:id="@+id/action_search"
    android:title="@string/buscar"
    app:actionViewClass="android.support.v7.widget.SearchView"
    app:showAsAction="always" />

<item
    android:id="@+id/alimentos_basket"
    android:orderInCategory="1"
    android:title="@string/alimentos_anadidos"
    app:showAsAction="always" />

在我的活动布局中,我什么都没有

In my activity layout I don't have anything

<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"
tools:context="com.irixgalicia.irixhealth.app.comidaDiaria.AnadirAlimentoActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay">

    </android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>

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

这些是我在其中充气的活动的代码

And these is the code of the activity where I inflate

    @Override
public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.menu_anadir_alimento, menu);
    final MenuItem menuItem = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuItem);
    searchView.setOnQueryTextListener(this);

    final MenuItem contadorItem = menu.findItem(R.id.alimentos_basket);
    contadorItem.setIcon(buildCounterDrawable(contadorAlimentos, R.drawable.ic_food_variant_white_36dp));

    return super.onCreateOptionsMenu(menu);
}

在我的布局中,我只有工具栏,而内部没有图标.

In my layout I only have the toolbar, not the icons inside.

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay">

    </android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>

任何人都知道如何实现我想要的东西.

Has anyone knows how to achieve what I'm looking for..

谢谢!

推荐答案

对属性showAsAction

<item
        android:id="@+id/action_search"
        android:title="search"
        app:actionViewClass="android.support.v7.widget.SearchView"
        android:icon="@drawable/ic_search"
        app:showAsAction="ifRoom|collapseActionView"/>

这篇关于在Android工具栏中的expandig searchview时将图标推开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆