Material Design风格SearchView实现语音搜索功能

Material Design风格SearchView实现语音搜索功能,弹出录音对话框效果也很漂亮。
但是这份代码支持在5.0以上的手机才能看到效果。
VoiceActivity 类实现录制语音功能。自定义一个MaterialSearchView

 searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                Snackbar.make(findViewById(R.id.container), "Query: " + query, Snackbar.LENGTH_LONG)
                        .show();
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                //Do some magic
                return false;
            }
        });

        searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {
            @Override
            public void onSearchViewShown() {
                //Do some magic
            }

            @Override
            public void onSearchViewClosed() {
                //Do some magic
            }
        });

运行效果:

相关代码

03-29 19:10