Android - 隐藏标题栏

Android - 隐藏标题栏 首页 / Android入门教程 / 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中的标题栏。

链接:https://www.learnfk.comhttps://www.learnfk.com/android/android-hide-title-bar-example.html

来源:LearnFk无涯教程网

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);


    }
}
输出:仅隐藏标题
android hide title bar example output 1
输出:隐藏TitleBar并启用全屏
android hide title bar example output 2

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

从0开始学微服务 -〔胡忠想〕

Kafka核心技术与实战 -〔胡夕〕

Swift核心技术与实战 -〔张杰〕

性能工程高手课 -〔庄振运〕

成为AI产品经理 -〔刘海丰〕

跟着高手学复盘 -〔张鹏〕

如何成为学习高手 -〔高冷冷〕

Web 3.0入局攻略 -〔郭大治〕

超级访谈:对话毕玄 -〔毕玄〕

好记忆不如烂笔头。留下您的足迹吧 :)