Skip to main content
 首页 » 编程设计

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

2024年12月31日12birdshome

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

请您参考如下方法:

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

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