Android: searchview icon does not appear in my toolbar

0

I'm trying to put my searchview icon in two views, for example in A and B, the problem is that it does not appear in the first view (A), but the searchview if it appears in my view (B) I'm using exactly the same code used in the view that works clearly changing the name of some variables so that it does not cause conflict, but I'm not really sure because it does not appear in the other.

menu_main.xml

<menu 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"
      tools:context=".ManageFragments.MainActivity">

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

Search_view.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 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:orientation="vertical"
    android:background="@color/GrayBackground"
    tools:context=".HomeFragments.SearchFragment">

    <android.support.v7.widget.Toolbar
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/Theme.AppCompat.Light"
        app:theme="@style/ThemeOverlay.AppCompat.ActionBar" />

        <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textStyle="bold"
        android:textColor="@android:color/black"
        android:layout_gravity="clip_vertical"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:visibility="invisible" />

</RelativeLayout>
    </ScrollView>
</LinearLayout>
    
asked by Phantom_strike 22.04.2017 в 07:01
source

1 answer

0

you have to inflate the menu or add it in this way:

   @Override
   public boolean onCreateOptionsMenu(Menu menu) {

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_main, menu);
    return super.onCreateOptionsMenu(menu);

   }
    
answered by 22.04.2017 в 17:36