I can’t remove the title bar from the android app

Asked

Viewed 5,266 times

0

I’ve tried using android:theme="@android:style/Theme.NoTitleBar", but when I run my app it gives error.

  • 1

    Edit your question and paste the error stack trace and, if possible, also add class where the error occurs.

2 answers

4

We have many ways to do this. One of them is by code, just add the following line in the method onCreate:

requestWindowFeature(Window.FEATURE_NO_TITLE);

Thus remaining:

@Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);
}

It is also possible to remove the title bar by file "AndroidManifest.xml". For this we must modify the Activity statement to declare that we do not want the bar. Just add/modify the attribute "android:theme" in the Activity statement, thus:

<activity android:theme="@android:style/Theme.Black.NoTitleBar">

So that all the activities of your application are without the label bar, modify the same attribute, but in "Application":

<application android:theme="@android:style/Theme.Black.NoTitleBar">

With the complexity of the applications we develop today, it is not uncommon to work with themes, which makes our work much easier. If you already work like this and do not want to keep adding the codes for removal in all your classes just modify your theme and put the attribute "android:windowsNoTitle"as true.

Take the example:

<resources>
  <style name="Theme.AppCompat.Light.NoActionBar" parent="@style/Theme.AppCompat.Light">
    <item name="android:windowNoTitle">true</item>
  </style>
</resources>

Source: http://www.henriquelacerda.com.br/2014/06/20/removendo-barra-de-titulo-aplicativo-android/

I hope I’ve helped.

  • I arranged the formatting for you. :)

  • @Victor vlw! :)

0

It’s simple, just add a line of code to onCreate.

@Override 
protected void onCreate(Bundle savedInstanceState) {          
    super.onCreate(savedInstanceState);
    getSupportActionBar().hide(); //Esta linha contém o código necessário.
    setContentView(R.layout.sua_activity);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.