【问题标题】:Android 3.2 remove title from action barAndroid 3.2 从操作栏中删除标题
【发布时间】:2012-03-30 11:19:20
【问题描述】:

我正在使用 Eclipse,Android 3.2。和运行 android x86 的虚拟机。 (v3.2)

我使用 Holo 主题,我想删除操作栏标题和图标。所以我这样做了

@Override
public void onCreate(Bundle savedInstanceState)
{
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test);
}

它工作正常,但是...

当应用程序启动时,我首先显示标题和图标,然后才看到它们消失。所以不是很漂亮。

如果我使用调试,我可以看到只有当我离开 onCreate 时,setDisplayShowTitleEnabled 才生效。

那么有没有办法在显示活动之前隐藏标题和图标?

谢谢。

【问题讨论】:

    标签: android


    【解决方案1】:

    在你的清单中

    <activity android:name=".ActivityHere"
         android:label="">
    

    【讨论】:

    • 警告:如果这是你的主要活动,你不想这样做。它将从您的启动器图标中删除标签。在这种情况下,肯尼斯的回答应该有效。
    • 是的,这是真的。我后来发现了。
    【解决方案2】:

    我通过在 android manifest 中设置“NoActionBar”全息主题,然后在 onCreate() 中设置正常的全息主题来解决这个问题。

    第 1 步:在 styles.xml 中,添加自定义主题资源。

    <resources>
        <style name="ActionBar.CustomTheme" parent="@android:style/Widget.Holo.ActionBar"/>
        <style name="CustomTheme" parent="@android:style/Theme.Holo">
            <item name="android:actionBarStyle">@style/ActionBar.CustomTheme</item>
        </style>
    </resources>
    

    第 2 步:在我的 android 清单文件中,我为应用程序设置主题,并为启动活动设置“NoActionBar”全息主题。

    <application
      android:theme="@style/CustomTheme
      ...
    
    <activity
      android:name="MainActivity"
      android:theme="@android:style/Theme.Holo.NoActionBar">
      ...
    

    第 3 步:在启动 Activity 的 onCreate()...

    @Override
    public void onCreate()(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setTheme(R.style.CustomTheme); // Set the custom theme which has the action bar.
        ActionBar actionBar = getActionBar();
        ...
    

    【讨论】: