如何使用Android TV在搜索片段中隐藏语音搜索图标

时间:2018-10-18 09:30:57

标签: android-tv amazon-fire-tv

如何在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);
                }
            }
        });

2 个答案:

答案 0 :(得分:3)

这是您可以在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;}

执行此操作将起作用。快乐编码:)

答案 1 :(得分:0)

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

  

所以你需要做

     
      
  • 实施setSpeechRecognitionCallback
  •   
  • 在AndroidManifest.xml中请求android.permission.RECORD_AUDIO
  •