Android 如何在加载 Activity 之前隐藏操作栏?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11434560/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to hide the actionbar before the Activity is loaded?
提问by damian
My goal is to show a splash screen on my applications startup. Right now what it will do is briefly show the actionbar with an otherwise blank page, then jump to the splash screen. I'm trying to figure out how to not show the beginning screen and just start with the splash screen. I'm trying to use these links for information on how to solve this.
我的目标是在我的应用程序启动时显示启动画面。现在它会做的是简单地显示带有空白页面的操作栏,然后跳转到初始屏幕。我想弄清楚如何不显示开始屏幕而只从启动屏幕开始。我正在尝试使用这些链接获取有关如何解决此问题的信息。
ActionBar Lag in hiding titleIn this one I'm assuming I can use the same type of method for hiding the actionbar by changing the theme, but I don't know what I would actually use as my style to do so.
ActionBar 隐藏标题滞后在这个中,我假设我可以使用相同类型的方法通过更改主题来隐藏操作栏,但我不知道我实际上会使用什么作为我的风格来这样做。
How to hide action bar before activity is created, and then show it again?and here it talks about adding a line to the manifest that would do it. Where in the manifest? Anywhere I put it did not do anything.
如何在创建活动之前隐藏操作栏,然后再次显示它?在这里它谈到在清单中添加一行来完成它。清单中的哪个位置?我把它放在任何地方都没有做任何事情。
回答by Mohsin Naeem
try this in manifest file
在清单文件中试试这个
<activity
android:name="yourActivityName"
android:label="your label"
android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen" >
</activity>
回答by Laranjeiro
Check this link Android: hide action bar while view load
检查此链接Android:在视图加载时隐藏操作栏
Code snippets from the link, incase the link breaks down, courtesy @kleopatra:
链接中的代码片段,以防链接失效,礼貌@kleopatra:
Setting the properties
windowNoTitle
to true on your theme will hide the ActionBar. use two different themes both extendingparent="Theme.AppCompat.Light"
in order to prevent NPE when using getSupportActionBar
将
windowNoTitle
主题上的属性设置为 true 将隐藏 ActionBar。使用两个不同的主题都扩展parent="Theme.AppCompat.Light"
以防止在使用 getSupportActionBar 时出现 NPE
set the styles as
将样式设置为
<style name="AppThemeNoBar" parent="Theme.AppCompat.Light"> <item name="android:windowNoTitle">true</item> </style> <style name="AppThemeBar" parent="Theme.AppCompat.Light"> <item name="android:windowNoTitle">false</item> </style>
Due to some odd behaviour on versions < 11, you need to add
if (Build.VERSION.SDK_INT < 11){ getSupportActionBar().hide(); }
inside activities that do not need the actionbar
<style name="AppThemeNoBar" parent="Theme.AppCompat.Light"> <item name="android:windowNoTitle">true</item> </style> <style name="AppThemeBar" parent="Theme.AppCompat.Light"> <item name="android:windowNoTitle">false</item> </style>
由于版本 < 11 上的一些奇怪行为,您需要添加
if (Build.VERSION.SDK_INT < 11){ getSupportActionBar().hide(); }
不需要操作栏的内部活动
回答by prototype0815
Delete the "android:label" entries in Manifest file, from application and the first activity which is loaded. In your case, the Splash activity. Sample...
从应用程序和加载的第一个活动中删除清单文件中的“android:label”条目。在您的情况下,Splash 活动。样本...
<application
android:allowBackup="true"
android:icon="@drawable/starticon"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo">
<activity
android:name=".ActivitySplash"
android:label="@string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
回答by M?ritzRo
Just add this code in your Activity in the onCreate function.
只需将此代码添加到您的 Activity 的 onCreate 函数中即可。
val actionBar = supportActionBar?.apply{hide()}