无法将Android标题栏隐藏在onCreate方法之外
我正在实现一个始终全屏运行且没有标题栏的应用程序。 在这种情况下,用户单击按钮并使用语音识别功能API。一个android本机窗口被调用来分析用户的声音。但是,标题栏再次可见。问题是我无法再次隐藏它,因为隐藏它的方法只在onCreate方法中起作用 下面是我调用voice API的方法,标题栏再次可见无法将Android标题栏隐藏在onCreate方法之外,android,eclipse,android-titlebar,Android,Eclipse,Android Titlebar,我正在实现一个始终全屏运行且没有标题栏的应用程序。 在这种情况下,用户单击按钮并使用语音识别功能API。一个android本机窗口被调用来分析用户的声音。但是,标题栏再次可见。问题是我无法再次隐藏它,因为隐藏它的方法只在onCreate方法中起作用 下面是我调用voice API的方法,标题栏再次可见 public void VoiceCaptureButtonClick(View v) { //- The title bar is properly hidden at this
public void VoiceCaptureButtonClick(View v) {
//- The title bar is properly hidden at this point.
//Code for calling the voice recognition API:
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Voice recognition Demo...");
startActivityForResult(intent, REQUEST_CODE);
//- Now the title bar is visible again, and I don't manage to hide it anymore.
// if I use the method requestWindowFeature(Window.FEATURE_NO_TITLE);
// I run into a exception : "requestFeature() must be called before adding content"
}
编辑:
下面是我用来隐藏标题栏并使应用程序全屏显示的代码,
它工作得很好,直到我调用上面的方法为止
<application
...
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
...
</application>
将android:theme=“@android:style/theme.NoTitleBar.”
添加到清单中的
,以完全删除标题栏。比如:
<activity
android:name=".Foo"
android:label="@string/foo"
android:theme="@android:style/Theme.NoTitleBar.">
编辑:
我现在明白了。当您调用startActivityForResult()
时,您的应用程序将不再处于控制状态,因为您已启动语音识别活动。因此,您的样式(隐藏标题栏等)不再发挥作用,Android将再次显示所有这些
您不能在此处使用requestFeature()
,因为Android只能在膨胀布局之前进行这些更改
似乎没有解决方案,因为调用startActivityForResult()
时,应用程序无法控制