---
title: "Android去掉TitleBar的方法"
author: "binyan17"
date: "2014-08-18T11:34:01Z"
tags: []
categories: ["移动开发"]
slug: "android-titlebar"
draft: false
lastmod: "2014-08-18T11:36:19Z"
id: 2105437
url: "https://binyan17.iteye.com/blog/2105437"
---

**原文请点击[这里](http://www.anbiji.com/index.php/archives/27)**

**第一种，在调用setContentView()之前插入代码：**

```
requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
setContentView(R.layout.activity_main);
```

 **第二种，在AndroidManifest.xml文件中配置Activity：**

 

```
<activity
    android:name="com.example.MainActivity"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
```

 

**第三种，修改res/value/style.xml文件，增加一个样式，然后在相应的activity中应用该样式:**

 

```
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowNoTitle">true</item>
</style>
```

 **定义完了一个style，接下来就是在AndroidManifest.xml中使用了：**

```
<application
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
```