【问题标题】:How to hide the actionbar before the Activity is loaded?如何在加载 Activity 之前隐藏操作栏?
【发布时间】:2012-07-11 14:12:28
【问题描述】:

我的目标是在我的应用程序启动时显示启动画面。现在它将做的是短暂地显示带有空白页面的操作栏,然后跳转到启动屏幕。我试图弄清楚如何不显示开始屏幕而只从启动屏幕开始。 我正在尝试使用这些链接获取有关如何解决此问题的信息。

ActionBar Lag in hiding title 在这篇文章中,我假设我可以使用相同类型的方法通过更改主题来隐藏操作栏,但我不知道我实际上会使用什么作为我的风格。

How to hide action bar before activity is created, and then show it again? 在这里它谈到了在清单中添加一行来做到这一点。清单在哪里?我把它放在任何地方都没有做任何事情。

【问题讨论】:

    标签: android android-actionbar


    【解决方案1】:

    在清单文件中试试这个

    <activity
            android:name="yourActivityName"
            android:label="your label"
            android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen" >
    
        </activity>
    

    【讨论】:

    • 如何在启动画面后恢复操作栏?
    • 您在哪部手机上测试?
    • HTC One XL。不过那应该没关系。我尝试使用 this.getApplication().setTheme(16973934);将主题更改回来,但它没有做任何事情
    • 从哪部手机我的意思是说哪个操作系统...但是崩溃的原因不应该是这个..如果您删除此行应用程序运行顺利?
    • 抱歉修复了崩溃,我在调用 getActionBar 时调用了 nullPointer。它运行良好,但在启动屏幕后我需要在应用程序中使用我的 actionBar。不知道如何找回它。
    【解决方案2】:

    查看此链接Android: hide action bar while view load

    链接中的代码 sn-ps,以防链接损坏,礼貌@kleopatra:

    在您的主题上将属性 windowNoTitle 设置为 true 将 隐藏操作栏。使用两个不同的主题都扩展 parent="Theme.AppCompat.Light" 以防止在使用 getSupportActionBar 时出现 NPE

    将样式设置为

    <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>
    

    由于版本

    如果 (Build.VERSION.SDK_INT

    在不需要操作栏的活动中

    【讨论】:

    • 请注意,link-only answers are discouraged,SO 答案应该是搜索解决方案的终点(相对于另一个参考中途停留,随着时间的推移往往会变得陈旧)。请考虑在此处添加独立的概要,并保留链接作为参考。
    【解决方案3】:

    从应用程序和加载的第一个活动中删除清单文件中的“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>
    

    【讨论】:

      【解决方案4】:

      只需将此代码添加到您的 Activity 的 onCreate 函数中即可。

      val actionBar = supportActionBar?.apply{hide()}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-01-19
        • 1970-01-01
        • 2014-03-18
        • 1970-01-01
        • 1970-01-01
        • 2013-02-02
        • 2015-09-17
        相关资源
        最近更新 更多