如何使用android Tv在searchfragment中隐藏语音搜索图标

问题描述 投票:2回答:2

如何隐藏android firetv中的语音搜索图标扩展了android.support.v17.leanback.app.SearchFragment库。当我扩展该搜索库时,它在我的代码中即将出现默认...现在我不想使用语音搜索功能...

下面的监听器默认:::

 setSpeechRecognitionCallback(new SpeechRecognitionCallback() {
            @Override
            public void recognizeSpeech() {
                Log.v(TAG, "recognizeSpeech");
                try {
                    Intent mSpeechRecognizerIntent = getRecognizerIntent();
                    mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, new Long(3000));
                    mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, new Long(2000));
                    startActivityForResult(mSpeechRecognizerIntent, REQUEST_SPEECH);
                    //startActivityForResult(getRecognizerIntent(), REQUEST_SPEECH);
                } catch (ActivityNotFoundException e) {
                    Log.e(TAG, "Cannot find activity for speech recognizer", e);
                }
            }
        });
android-tv amazon-fire-tv
2个回答
4
投票

以下是您在searchFragment中隐藏语音搜索的方法。

在searchFragment中,您需要覆盖onCreateView。

 @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = super.onCreateView(inflater, container, savedInstanceState);
    FrameLayout searchFrame = root.findViewById(R.id.lb_search_frame);
   SearchBar mSearchBar = searchFrame.findViewById(R.id.lb_search_bar);
   SpeechOrbView mSpeechOrbView = mSearchBar.findViewById(R.id.lb_search_bar_speech_orb);


    if (mSpeechOrbView != null) {
        mSpeechOrbView.setOrbIcon(ContextCompat.getDrawable(getActivity(),
                R.drawable.ic_search_sel));
        mSpeechOrbView.setVisibility(View.GONE);
    }return root;}

这样做会有效。快乐编码:)


0
投票

基于此link,Google具有默认语音搜索功能。如果您不通过setSpeechRecognitionCallback(SpeechRecognitionCallback)提供回调,将使用内部语音识别器,您的应用程序将需要请求android.permission.RECORD_AUDIO

所以你需要做任何一件事

  • 实施setSpeechRecognitionCallback
  • 在AndroidManifest.xml上请求android.permission.RECORD_AUDIO
© www.soinside.com 2019 - 2024. All rights reserved.