1. Java代码实现

@Override  public void onCreate(Bundle savedInstanceState) {          super.onCreate(savedInstanceState);            requestWindowFeature(Window.FEATURE_NO_TITLE);             setContentView(R.layout.main);          //...  }  

(留意这语句所在的位置的,似乎所有requestWindowFeature的操作都要放在setContentView的前面。
但使用这种方法,用户体验不太好,在Activity将要显示时,仍然会出现title bar,然后再去掉的。)

2. 自定义style配置文件

在\res\values里面的style.xml添加:
<?xml version="1.0" encoding="utf-8"?>  <resources>          <style name="NoTitle" parent="android:Theme">                  <item name="android:windowNoTitle">true</item>          </style>  </resources>  

然后在AndroidManifest.xml文件里,给需要去掉title bar的activity的节点上加上android:theme="@style/NoTitle,代码如下:
<activity android:name=".MainActivity"                      android:configChanges="orientation|keyboardHidden"                      android:theme="@style/NoTitle" />  

3. 直接在AndroidManifest.xml中进行修改

我们可以无需自定义style配置的,直接调用系统的就行了:
<activity android:name=".MainActivity"                      android:configChanges="orientation|keyboardHidden"                      android:theme="@android:style/Theme.NoTitleBar" />  

如果我们要设置整个Application都去掉title bar,那么就设置application:
<application android:icon="@drawable/lightbulb" android:label="@string/app_name"                      android:theme="@android:style/Theme.NoTitleBar">  



更多相关文章

  1. 动态调整Android(安卓)surfaceView 视图上下层问题
  2. android 小米时钟的实现
  3. Android(安卓)一行代码全局应用内屏蔽系统设置字体和显示大小
  4. Android控件布局属性大全
  5. 第五次Android课堂笔记
  6. Android布局管理
  7. Android(安卓)Recyclerview轻松实现分割线ItemDecoration
  8. Android(安卓)Dialog 使用 ConstraintLayout 约束布局宽度异常原
  9. Android(安卓)- 永不锁屏,开机不锁屏,删除设置中休眠时间选项

随机推荐

  1. Android(安卓)CoordinatorLayout使用
  2. ImageView中显示网络图片,图片变模糊?
  3. 自定义开关
  4. Error generating final archive: java.i
  5. 关于android:targetSdkVersion
  6. ReactNative 中 android按两次返回键退出
  7. ListView的Item中CheckBox焦点优先于List
  8. Android(安卓)Studio上报错java.net.Unkn
  9. android实现气泡聊天
  10. Android中TrafficStats流量监控类