Android开发中如何去掉app标题栏的实现
作者:我想月薪过万 时间:2023-07-25 00:38:27
方法
一、若创建Activity时继承的是 Activity:
第一种:常用的一种方法:
requestWindowFeature(Window.FEATURE_NO_TITLE);//这行代码必须写在setContentView()方法的前面
package com.wust.selfviewgroup;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); //这个方法必须写在 setContentView 的前面,了解源码的同学应该知道其原因
setContentView(R.layout.activity_main);
}
}
第二种:在AndroidManifest.xml文件中作如下配置
<application android:theme="@android:style/Theme.NoTitleBar">
测试结果:在实际测试中,我发现继承 Activity 本身就没有标题栏,以上两种方法只是提供一种解决思路。
二、创建Activity时继承的是 AppCompatActivity:
第一种:
getSupportActionBar().hide();//这行代码必须写在setContentView()方法的后面
package com.wust.selfviewgroup;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
getSupportActionBar().hide(); //这个方法要写在 setContentView() 之后
}
}
第二种:可以在AndroidManifest.xml文件中作如下配置
<application android:theme="@style/Theme.AppCompat.NoActionBar">
注意事项
前面提供的方法不能混用,要求的顺序不能错,要不然会导致方法失效,得不到想要的结果
来源:https://blog.csdn.net/qq_41885673/article/details/115773427
标签:Android,去掉,app标题栏
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android实现简单时钟View的方法
2022-10-21 18:36:00
![](https://img.aspxhome.com/file/2023/6/137146_0s.gif)
elasticsearch java客户端action的实现简单分析
2022-04-25 05:39:45
![](https://img.aspxhome.com/file/2023/4/83424_0s.jpg)
java并发之原子操作类和非阻塞算法
2022-04-13 04:39:01
Java优先队列(PriorityQueue)重写compare操作
2022-10-02 03:59:12
springboot集成shiro权限管理简单实现
2023-10-27 13:39:02
![](https://img.aspxhome.com/file/2023/9/79959_0s.png)
Java运行时数据区概述详解
2023-10-08 07:00:10
![](https://img.aspxhome.com/file/2023/0/69130_0s.png)
1秒钟实现Springboot 替换/写入 word文档里面的文字、图片功能
2022-05-08 18:35:48
![](https://img.aspxhome.com/file/2023/7/82437_0s.png)
微信公众号 网页授权登录及code been used解决详解
2023-02-06 18:49:00
![](https://img.aspxhome.com/file/2023/8/65768_0s.png)
Springboot 整合RabbitMq(用心看完这一篇就够了)
2023-11-23 05:27:17
![](https://img.aspxhome.com/file/2023/3/59753_0s.jpg)
C/C++ 左移<<, 右移>>的作用及说明
2021-12-30 01:42:59
![](https://img.aspxhome.com/file/2023/9/107399_0s.jpg)
c# 日历控件的实现
2022-08-21 11:02:22
![](https://img.aspxhome.com/file/2023/0/122640_0s.gif)
详解Spring ApplicationContext加载过程
2023-07-17 01:07:43
java并发编程专题(五)----详解(JUC)ReentrantLock
2023-12-01 04:04:09
Android主线程和子线程区别详解
2023-12-18 17:33:38
Android输入法弹出时覆盖输入框问题的解决方法
2023-02-06 06:36:52
Java Stream流的常见生成和操作方法总结
2023-08-26 12:06:21
spring-cloud入门之eureka-client(服务注册)
2023-12-16 22:42:51
![](https://img.aspxhome.com/file/2023/4/90974_0s.png)
spring cloud 配置中心native配置方式
2022-06-13 00:36:32
Java线程池Executor用法详解
2022-02-13 01:21:16
![](https://img.aspxhome.com/file/2023/2/62812_0s.jpg)
java简单解析xls文件的方法示例【读取和写入】
2022-04-15 19:30:43