【问题标题】:How to hide voice search icon in searchfragment using android Tv如何使用 android Tv 在 searchfragment 中隐藏语音搜索图标
【发布时间】:2019-03-23 02:07:04
【问题描述】:

如何在 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


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

      所以你需要做任何一个

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

      【讨论】:

        【解决方案3】:

        老问题,但最终添加到 Leanback 库中:

        使 SearchSupportFragment 的语音识别器成为可选

        https://developer.android.com/jetpack/androidx/releases/leanback?hl=nb#1.1.0-rc01

        【讨论】:

          猜你喜欢
          • 2018-07-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-03-17
          • 2016-01-19
          • 2023-02-21
          相关资源
          最近更新 更多