Is there any way to remove notification/status bar, but not in onCreate?

独自空忆成欢 提交于 2019-12-11 16:46:43

问题


As far as I know, it is possible to hide the notification/title bar, once the activity is visible (has content) , But... maybe I'm wrong?

Is there any way to hide it after the activity is visible?


回答1:


You can define the activity to use a theme that eliminates the notification/title bar. For instance, you can add this as an attribute to your <activity ... > tag in AndroidManifest.xml:

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

The presence of a title cannot be changed once you have called setContentView(). The only way to hide the title bar after your activity has started is to restart the activity with a modified intent. Do something like this:

Intent intent = getIntent();
overridePendingTransition(0, 0);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
intent.putExtra("NoTitle", true);
finish();

overridePendingTransition(0, 0);
startActivity(intent);

Then in onCreate() test whether the "NoTitle" extra is present in the intent and make the appropriate call to requestWindowFeature() before calling setContentView().



来源:https://stackoverflow.com/questions/8792101/is-there-any-way-to-remove-notification-status-bar-but-not-in-oncreate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!