Android Studio:删除默认页眉

5
我刚开始学习运行在Windows 7上的Android Studio(版本2.0)。当我创建一个新项目(空活动模板)时,Android Studio会在项目顶部放置一个标题。如何删除标题?
以下是问题的图片。我想要去掉“我的贺卡”标题。

enter image description here

5个回答

7
您只需像下面这样简单导航....
应用程序 -> res -> values -> styles.xml
找到 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 行。 Theme.AppCompat.Light.DarkActionBar 行显示了您的活动将看起来如何。
有许多可用的主题。只需删除 DarkActionBar 并按 Cntrl+Space 键以探索其他主题即可。在您的情况下,您不想要称为 Android 术语中的 ActionBarHeader
因此,只需将主题更改为 Theme.AppCompat.Light.NoActionBar 即可完成。
要更深入地了解主题工作方式和 Android 的其他课程,请尝试 Pluralsight。转到下面的链接并获得 6 个月的免费订阅。这是一个非常好的学习任何技术的网站。 Pluralsight 6 Months Subscription

3

答案已经给出,但我还想补充一点,如果您不想在活动顶部有任何类型的操作栏,只需执行以下操作。 转到您的res->values->styles.xml并添加以下xml代码:

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">#3F51B5</item>
        <!-- Light Indigo -->
        <item name="colorPrimaryDark">#3949AB</item>
        <!-- Dark Indigo -->
        <item name="colorAccent">#00B0FF</item>
        <!-- Blue -->
    </style>
    <style name="AppTheme" parent="AppTheme.Base"></style>
</resources>

在任何您想要的活动中,可以通过在清单文件中使用 android:theme=@style/AppTheme 的方式来引用主题并将其应用到样式中。

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".DetailActivity"
            android:parentActivityName=".MainActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
    </application>

2

您可以使用以下方法隐藏工具栏:

getActionBar().hide();

或者
getSupportActionBar().hide();

你会在哪里调用getActionBar方法? - Argent
在setContentView()之后。 - David Hackro
不起作用。我猜这是在onCreate方法中。 - Argent
你要扩展Activity还是AppCompatActivity? - David Hackro
我扩展了AppCompatActivity。顺便说一下,当我说“我”时,这是由Android Studio生成的代码。除了添加调用getActionBar()。hide()的行之外,我没有改动它,正如你建议的那样。 - Argent

1

对于更新版

应用程序 -> 资源 -> 值 -> 主题 -> themes.xml

这也取决于手机是否处于夜间模式。

然后你需要修改两个文件:

  1. themes.xml
  2. themes.xml (night)

with parent="Theme.MaterialComponents.DayNight.NoActionBar"


0

只需删除AppCompatActivity并将其扩展为Activity即可。


请详细说明您的问题。 - Shashank

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接