Forum Xamarin.Android

Appcompact searchview whit voice button

I would like to implement a voice button in a searchview but I can not see the button.
This is my code:
using System;

using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Support.V4.Widget;
using Android.Support.V7.App;
using Android.Support.V7.Widget;
using Android.Support.Design.Widget;

namespace ZI_4Android
{
[Activity(Label = "Zippy Infinity", MainLauncher = true, LaunchMode = Android.Content.PM.LaunchMode.SingleTop)]
[IntentFilter(new[] { Intent.ActionSearch, Intent.ActionView, "com.google.android.gms.actions.SEARCH_ACTION" }, Categories = new[] { Intent.CategoryDefault })]
[MetaData("android.app.searchable", Resource = "@drawable/searchable")]
public class ac_ClientiMain : AppCompatActivity
{
DrawerLayout drawerLayout;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);

    // Create UI
    SetContentView(Resource.Layout.ClientiMain);
    drawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);

    // Init toolbar
    var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbarClienti);
    SetSupportActionBar(toolbar);

    // Attach item selected handler to navigation view
    var navigationView = FindViewById<NavigationView>(Resource.Id.nav_view);
    navigationView.NavigationItemSelected += NavigationView_NavigationItemSelected;

    // Create ActionBarDrawerToggle button and add it to the toolbar
    var drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, Resource.String.open_drawer, Resource.String.close_drawer);
    drawerLayout.SetDrawerListener(drawerToggle);
    drawerToggle.SyncState();


    Android.Support.V4.App.Fragment fragment = new fragment_Clienti();
    SupportFragmentManager.BeginTransaction()
    .Replace(Resource.Id.content_frame, fragment)
    .Commit();

    HandleIntent(Intent);

}



void NavigationView_NavigationItemSelected(object sender, NavigationView.NavigationItemSelectedEventArgs e)
{
    switch (e.MenuItem.ItemId)
    {
        case (Resource.Id.nav_home):
            // React on 'Home' selection
            break;
        case (Resource.Id.nav_messages):
            // React on 'Messages' selection
            break;
        case (Resource.Id.nav_friends):
            // React on 'Friends' selection
            break;
        case (Resource.Id.nav_discussion):
            // React on 'Discussion' selection
            break;
    }

    // Close drawer
    drawerLayout.CloseDrawers();
}

protected override void OnNewIntent(Intent intent)
{
    base.OnNewIntent(intent);
    HandleIntent(intent);
}

private void HandleIntent(Intent intent)
{
    if (Intent.ActionSearch != intent.Action &&  "com.google.android.gms.actions.SEARCH_ACTION" != intent.Action)
        return;
    var query = intent.GetStringExtra(SearchManager.Query);
    Toast.MakeText(this, "You searched: " + query, ToastLength.Short).Show();

}
public override bool OnCreateOptionsMenu(IMenu menu)
{
    MenuInflater inflater = MenuInflater;
     inflater.Inflate(Resource.Menu.clienti_std, menu);

    var searchMenu = menu.FindItem(Resource.Id.menu_search);


    var searchView = Android.Support.V4.View.MenuItemCompat.GetActionView(searchMenu).JavaCast<Android.Support.V7.Widget.SearchView>();

    var searchManager = (SearchManager)GetSystemService(SearchService);
    searchView.SetSearchableInfo(searchManager.GetSearchableInfo(ComponentName));



    searchView.QueryTextSubmit += SearchView_QueryTextSubmit;


    return true;
}

public override bool OnOptionsItemSelected(IMenuItem item)
{
    switch (item.ItemId)
    {
        case Resource.Id.menu_search:
            OnSearchRequested();
            return true;
    }

    return base.OnOptionsItemSelected(item);
}

private void SearchView_QueryTextSubmit(object sender, Android.Support.V7.Widget.SearchView.QueryTextSubmitEventArgs e)
{
    Toast.MakeText(this, "You searched: " + e.Query, ToastLength.Short).Show();
}

}

}

Sign In or Register to comment.