Android隐藏标题栏
在此示例中,无涯教程将解释如何隐藏标题栏以及如何在全屏模式下显示内容。
RequestWindowFeature(Window.FEATURE_NO_TITLE)必须调用Activity方法来隐藏标题。但是,必须在SetContentView方法之前调用。
隐藏标题栏
getSupportActionBar()方法用于检索actionBar类的实例。调用ActionBar类的hide()方法隐藏标题栏。
requestWindowFeature(Window.FEATURE_NO_TITLE);//将隐藏标题 getSupportActionBar().hide(); //隐藏标题栏
实现全屏模式
setFlags()窗口类方法用于全屏模式下显示内容。需要通过setFlags方法中传递 WindowManager.LayoutParams.FLAG_FULLSCREEN 常量。
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //全屏显示活动
隐藏标题栏和全屏示例
让无涯教程看看完整的代码来隐藏Android中的标题栏。
activity_main.xml<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="first.javatpoint.com.hidetitlebar.MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent"/> </android.support.constraint.ConstraintLayout>
File: MainActivity.java
package first.learnfk.com.hidetitlebar; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Window; import android.view.WindowManager; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); //will hide the title getSupportActionBar().hide();//hide the title bar this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //enable full screen setContentView(R.layout.activity_main); } }
输出:仅隐藏标题

输出:隐藏TitleBar并启用全屏
祝学习愉快! (发现内容有误?请选中要编辑的内容 -> 右键 -> 修改 -> 提交!帮助我们改进教程质量)
精选教程推荐
👇 以下精选教程可能对您有帮助,拓展您的技术视野
暂无学习笔记,成为第一个分享的人吧!
您的笔记将帮助成千上万的学习者