【问题标题】:How to disable the title on the ActionBar in Main Launcher Activity如何在主启动器活动中禁用 ActionBar 上的标题
【发布时间】:2016-12-16 15:59:53
【问题描述】:

我检查了这个问题,找不到答案。 我检查了 3 个地方,在我的 Android 手机或应用程序中的 3 个单独的地方显示标签。

  1. 在应用的标志下
  2. 在显示活动应用程序的应用程序进程中,(您可以从该窗口关闭应用程序进程)
  3. 在最烦人的地方,“splash”操作栏标题(它发生在主活动 UI 开始之前,当它加载活动时 onCreate 我相信),我们大多数人通常都想摆脱它。

这三个地方是:

<application
    android:name=".Application"
    android:icon="@mipmap/icon"
    android:label="@string/app_name" <!-- 1--- the first place-->
    android:theme="@style/AppTheme">

    <activity
        android:name=".LoadingActivity"
        android:label="@string/app_name" <!-- 2--- the second place-->
        android:theme="@style/AppTheme.NoActionBar">

        <intent-filter android:label="@string/app_name"> <!-- 3--- the third place-->
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

我检查了我的手机 (LG4 - android 5.1)。

我在操作栏和进程上看到了地方 2 打印,但在手机的应用程序图标下放置了 3 打印。

但是!当我签入另一部手机时(夏威夷 P9 - android 6.0)

我看到地方 2 印在手机的应用程序图标下,不像 LG4 中的地方 3 是这样做的。


我实际检查它的主要原因是我不希望标题出现在操作栏中,而我希望它出现在应用程序图标和进程中。

专家有什么帮助吗?

【问题讨论】:

    标签: android xml android-actionbar


    【解决方案1】:

    很抱歉在答案部分发表评论,但那是因为声誉低下,你会添加你的 onCreate 方法代码以告诉你如何使用

    .setTitle(" ");
    

    您将标题设置为空白以使应用名称不会出现,如果这对您有帮助的话

    【讨论】:

      【解决方案2】:

      1) 您可以覆盖操作栏,以使用您的自定义操作栏布局。

      getSupportActionBar.setCustomView("your custom view");
      

      2) 如果你只是想隐藏标题,你可以使用

      设置标题
      getSupportActionBar.setTitle("");
      getSupportActionBar.setSubtitle(""); 
      

      【讨论】:

      • @LamaTo 如果这对您有帮助,您能否将其标记为正确答案?
      【解决方案3】:
      if (getSupportActionBar() != null) {
                  getSupportActionBar().setTitle("");
      }
      

      【讨论】:

      • 最好在代码周围包含一些解释/上下文,而不是只提供代码答案。
      【解决方案4】:
          if (getSupportActionBar() != null) {
              getSupportActionBar().setDisplayShowTitleEnabled(false);
          }
      

      【讨论】:

        【解决方案5】:

        根据你给我的答案,我想出了一种方法来做我需要的事情。

        我将主启动器活动更改为从 AppCompatActivity 扩展而不是 Activity,这样我就可以使用您列出的建议。 (虽然我仍然想知道如何使用常规 Activity 来做到这一点)

        风格主题对我来说也足够了,而且它的工作方式更整洁!

        <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
            <item name="android:background">@color/colorPrimaryDark</item>
            <item name="background">@color/colorPrimaryDark</item>
        </style>
        
        <style name="MyAppTheme.NoActionBar" parent="Theme.AppCompat.NoActionBar">
            <item name="colorPrimary">@color/colorPrimaryDark</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="android:statusBarColor">@color/colorPrimaryDark</item>
            <item name="windowActionBar">false</item>
            <item name="windowNoTitle">true</item>
            <item name="android:windowBackground">@color/colorPrimaryDark</item>
            <item name="android:actionBarItemBackground">@color/colorPrimaryDark</item>
            <item name="android:actionBarStyle">@style/MyActionBar</item>
        </style>
        

        这个xml样式,在所有想要的地方修复了选中的PrimaryColor,并且不会在主启动活动加载操作栏中显示标题,而在图标下和进程中显示它!

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-04-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多