Android项目去掉标题栏操作

来源:互联网 发布:清华java培训 编辑:程序博客网 时间:2024/05/16 06:17

Android项目去掉标题栏操作

目前市面上的大部分Android APK都已经取消标题栏,Android的Activity中去掉标题栏或者隐藏标题栏是怎么做到的呢?
下面我们进入正题,教程开始了,请没有上车的朋友抓紧时间买票了。
方法一:通过java代码实现
在需要隐藏标题栏的Activity中的onCreate方法中,添加如下代码:

    requestWindowFeature(Window.FEATURE_NO_TITLE);

示例代码:

   protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        requestWindowFeature(Window.FEATURE_NO_TITLE);      //去头操作    }

方法二:通过清单文件设置
上面的通过在类的代码中写只能去掉一个activity的标题栏,很多时候我们是所有的Activity标题栏都不需要的。我们通过修改application节点中android:theme=”@style/AppTheme”
按着Ctrl键+鼠标左键 进入styles.xml中找到

    <style name="AppTheme" parent="AppBaseTheme">        <!-- All customizations that are NOT specific to a particular API-level can go here. -->    </style>

在style节点中添加

    <item name="android:windowNoTitle">true</item>

示例代码:

    <style name="AppTheme" parent="AppBaseTheme">        <!-- All customizations that are NOT specific to a particular API-level can go here. -->        <item name="android:windowNoTitle">true</item>    </style>

好了,就到这里了,欢迎大家一起学习!~

作者:YouRenLK
博客地址:http://blog.csdn.net/zhanglink617

0 0
原创粉丝点击