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

vin*_*h48 4 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);
                }
            }
        });
Run Code Online (Sandbox Code Playgroud)

val*_*abh 5

以下是在 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;}
Run Code Online (Sandbox Code Playgroud)

这样做它会起作用。快乐编码:)


abi*_*ita 0

根据此链接,谷歌有默认的语音搜索。如果您不提供回调via setSpeechRecognitionCallback(SpeechRecognitionCallback),则将使用您的应用程序需要请求的内部语音识别器android.permission.RECORD_AUDIO

所以你需要做

  • 实施setSpeechRecognitionCallback
  • android.permission.RECORD_AUDIOAndroidManifest.xml 上的请求