Android 3.2从操作栏中删除标题

twe*_*sat 9 android

我正在使用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);
}
Run Code Online (Sandbox Code Playgroud)

它工作正常,但......

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

如果我使用debug,我只能在离开onCreate时才能看到setDisplayShowTitleEnabled生效.

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

谢谢.

eas*_*ese 17

在你的清单中

<activity android:name=".ActivityHere"
     android:label="">
Run Code Online (Sandbox Code Playgroud)

  • 警告:如果这是您的主要活动,您不想这样做.它将从Launcher图标中删除标签.在这种情况下,Kenneth的答案应该有效. (10认同)

Anu*_*oft 9

我通过在android清单中设置"NoActionBar"holo主题,然后在onCreate()中设置正常的holo主题来解决这个问题.

第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>
Run Code Online (Sandbox Code Playgroud)

第2步:在我的android清单文件中,我为应用程序设置主题,为启动活动设置"NoActionBar"holo主题.

<application
  android:theme="@style/CustomTheme
  ...

<activity
  android:name="MainActivity"
  android:theme="@android:style/Theme.Holo.NoActionBar">
  ...
Run Code Online (Sandbox Code Playgroud)

第3步:在启动活动的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();
    ...
Run Code Online (Sandbox Code Playgroud)