在此示例中,无涯教程将解释如何隐藏标题栏以及如何在全屏模式下显示内容。
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>
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); } }
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)