How to hide the title bar that comes with the system in Android Studio software

Table of contents

1. Realization effect

2. Development environment

3. Implementation method

①First create a new project

②Open the Activity where you need to hide the title bar

③Let’s take a look at the normal display effect

④Then write code in onCreate

⑤Click to run the query to see the effect

3. Android Studio template


1. Realization effect

2. Development environment

3. Implementation method

        In the Android Studio software, hiding the system's own title bar can be completed by following the following steps:

①First create a new project

②Open the Activity where you need to hide the title bar

③Let’s take a look at the normal display effect

        Here we can see that every newly created project will have a title bar.

④Then write code in onCreate

        First, you need to obtain an ActionBar instance. ActionBar is a component used to display the application title and other action items.
        Then, use the following line of code to get the ActionBar instance in your Activity:

ActionBar supportActionBar = getSupportActionBar();

        Next, you need to check if the ActionBar is null to make sure it exists. If the ActionBar exists, you can call the hide() method to hide the title bar. The code is as follows:

if (supportActionBar != null) {
    supportActionBar.hide();
}

⑤Click to run the query to see the effect

        After completing the above steps, the title bar that comes with the system will be hidden. This allows you to customize your app's title bar or use other ways to display your app's information and action items.

3. Android Studio template

        ✨You can also follow Gong Zonghao's "Programming Learning". There are many high-quality open source projects and more programming materials in the menu bar Waiting for you to learn.

Guess you like

Origin blog.csdn.net/qq_29823791/article/details/135030299