隐藏仅用于一项活动的ActionBar标题 [英] Hide ActionBar title just for one activity

查看:45
本文介绍了隐藏仅用于一项活动的ActionBar标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将主题应用于整个应用程序,则会成功隐藏ActionBar标题:

If I apply theme for whole application it hides ActionBar title successfully:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/ActionBarStyle</item>
</style>

<style name="ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar.Solid">
    <item name="android:displayOptions">showHome|useLogo</item>
</style>
</resources>

分配清单:

    <application
    android:name="myapp"
    android:allowBackup="true"
    android:icon="@drawable/action_bar_icon"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

我需要仅在一项活动中隐藏ActionBar标题.

I need ActionBar title hidden just in one activity.

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
 ...other things...
</style>

<style name="MainActivityTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/ActionBarStyle</item>
</style>

<style name="ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar.Solid">
    <item name="android:displayOptions">showHome|useLogo</item>
</style>
</resources>

为一项活动明确设置此主题:

<LinearLayout     xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   tools:context=".MainActivity"
   android:id="@+id/mainLayout"
   android:orientation="vertical"
   android:theme="@style/MainActivityTheme">

,并且仍在MainActivity ActionBar中显示标题.我知道如何在Java中隐藏标题,我需要知道我在XML中做错了什么.

and it still shows title in MainActivity ActionBar. I know how to hide the title in java, I need to know what I do wrong here in XML.

推荐答案

在清单中的活动上设置主题.

Set the theme on your activity in the manifest.

<activity
    android:name=".MyActivity"
    android:theme="@style/MainActivityTheme" />

这篇关于隐藏仅用于一项活动的ActionBar标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆