package com.pythoncat;

import android.app.SearchManager;
import android.content.ComponentName;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SearchView;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.pythoncat.utils.ToastHelper;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        MenuItem searchItem = menu.findItem(R.id.menu_search);
        // searchItem.expandActionView();
        SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        SearchManager searchManager =
                (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        ComponentName componentName = getComponentName();
        searchView.setSearchableInfo(
                searchManager.getSearchableInfo(componentName));
        searchView.setQueryHint("想要搜索什么呢？");
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String s) {
                // 点击输入法的搜索按键触发的回调！
                ToastHelper.show(getApplicationContext(), "我主动搜索了！！！");
                return true;
            }

            @Override
            public boolean onQueryTextChange(String s) {
                if (s == null || s.length() <= 0)
                    return false;
                // 点击输入法的搜索按键触发的回调！
                ToastHelper.show(getApplicationContext(), "文本框改变了.....");
                return true;
            }
        });
        searchView.setOnCloseListener(new SearchView.OnCloseListener() {
            @Override
            public boolean onClose() {
                return true;
            }
        });
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.menu_add) {
            Toast.makeText(getApplicationContext(), "add=== ", Toast.LENGTH_SHORT).show();
            return true;
        } else if (item.getItemId() == R.id.menu_remove) {
            Toast.makeText(getApplicationContext(), "remove=== ", Toast.LENGTH_SHORT).show();
            return true;
        } else {
            return super.onOptionsItemSelected(item);
        }
    }
}

@@ -869,24 +869,50 @@
 ();%0A        
+android.support.v7.widget.
 SearchView s
@@ -1790,32 +1790,27 @@
      // 
-%E7%82%B9%E5%87%BB%E8%BE%93%E5%85%A5%E6%B3%95%E7%9A%84%E6%90%9C%E7%B4%A2%E6%8C%89%E9%94%AE%E8%A7%A6%E5%8F%91
+%E8%BE%93%E5%85%A5%E6%A1%86%E5%86%85%E5%AE%B9%E6%94%B9%E5%8F%98%E6%97%B6
 %E7%9A%84%E5%9B%9E%E8%B0%83
-%EF%BC%81
 %0A       

modify some