Activity与AppCompatActivity去掉标题栏

2018-10-17 17:12:18

Activity与AppCompatActivity去掉标题栏

Activity去标题栏

1.代码中实现


requestWindowFeature(Window.FEATURE_NO_TITLE);

//这句代码必须写在setContentView()前面

1

2

2.在清单文件(manifest.xml)里面实现


<application android:icon="@drawable/icon"   

        android:label="@string/app_name"   

        android:theme="@android:style/Theme.NoTitleBar"> 


<!--或者只对某个activity设置-->

<activity android:name="xxxx.xxxxx.xxxx.activity"

            android:theme="@android:style/Theme.NoTitleBar"/>

1

2

3

4

5

6

7

3.在style.xml文件里定义


<?xml version="1.0" encoding="UTF-8" ?>  

<resources>  

    <style name="notitle">  

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

    </style>   

</resources>

1

2

3

4

5

6

然后在manifest.xml中引用就可以了


<application android:icon="@drawable/icon"   

        android:label="@string/app_name"   

        android:theme="@style/notitle"> 


<!--或者只对某个activity设置-->

<activity android:name="xxxx.xxxxx.xxxx.activity"

            android:theme="@style/notitle"/>

1

2

3

4

5

6

7

AppCompatActivity去标题栏

1.代码中实现,这里有两种方式


//方式一:这句代码必须写在setContentView()方法的后面

getSupportActionBar().hide();


//方式二:这句代码必须写在setContentView()方法的前面

supportRequestWindowFeature(Window.FEATURE_NO_TITLE);

1

2

3

4

5

2.在清单文件(manifest.xml)里面实现


<application

   android:theme="@style/Theme.AppCompat.NoActionBar">


<!--或者只对某个activity设置-->

<activity android:name="xxxx.xxxxx.xxxx.activity"

            android:theme="@style/Theme.AppCompat.NoActionBar"/>

--------------------- 

作者:jiejingguo 

来源:CSDN 

原文:https://blog.csdn.net/jiejingguo/article/details/80133880?utm_source=copy 

版权声明:本文为博主原创文章,转载请附上博文链接!

  • 2023-08-19 18:57:08

    强制杀死nginx进程简单粗暴

    nginx: [error] open() "/run/nginx.pid" failed (2: No such file or directory),最简单的办法,杀死nginx进程,重启

  • 2023-09-21 16:49:06

    用webpack.ProvidePlugin来解决Photo-Sphere-Viewer旧版本浏览器兼容问题

    上篇文章已经搭建了最基本的项目,我用手机下载了一个版本62.点开头的chrome apk来测试。 果真白屏,啥也没有,也看不到报错信息。 赶紧安装 vconsole ,重启,刷新,依然白屏,连vconsole也没有。这可咋弄。 想了下,这浏览器老的是可以呀,还得修改编译参数,加大es5的处理。 根目录有一个配置文件 .browserslistrc 里面的配置如下