Lugarini
Lugarini

Reputation: 802

Android - How to remove app name from ActionBar

This is my app:

enter image description here

Now i want to remove the app name from my ActionBar...
I want it like this:

enter image description here

my code:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:myapp="http://schemas.android.com/apk/res-auto" >

    <item
        android:id="@+id/phone"
        android:title="@string/phone"
        android:icon="@drawable/phone"
        myapp:showAsAction="ifRoom" />

    <item
        android:id="@+id/computer"
        android:title="@string/computer"
        android:icon="@drawable/computer"
        myapp:showAsAction="ifRoom"  />


</menu>

Upvotes: 13

Views: 15049

Answers (8)

Ot&#225;vio Dutra
Ot&#225;vio Dutra

Reputation: 1

Nowadays you can just set this inside the onCreate

supportActionBar?.hide()

Upvotes: 0

L.Ainsworth
L.Ainsworth

Reputation: 1

Just write this:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
    WindowManager.LayoutParams.FLAG_FULLSCREEN);

    getSupportActionBar().hide();

    setContentView(R.layout.activity_main);
}

Upvotes: 0

Akash Mondal
Akash Mondal

Reputation: 21

For Android 4.2.1 edit the default theme NoActionnBar and add this code in MainActivity.java file

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (getSupportActionBar() != null) {
        getSupportActionBar().hide();
    }
}

Upvotes: 2

John T
John T

Reputation: 1082

I've seen some questions about the location etc. Here is the complete solution. Use this in onCreate();

    setContentView(R.layout.activity_main);

    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Set title to false AFTER toolbar has been set
    try
    {
        getSupportActionBar().setDisplayShowTitleEnabled(false);
    }
    catch (NullPointerException e){}

Upvotes: 4

Alex
Alex

Reputation: 101

If you want to hide it use this code

getSupportActionBar().setDisplayShowTitleEnabled(false)

or if you want to change the name use this

getSupportActionBar().setTitle("type yor title here");

Upvotes: 6

SilentKnight
SilentKnight

Reputation: 14031

You could try setTitle(""). If you are using ActionBar or ToolBar, then call bar.setTitle("") or :

bar.setDisplayShowTitleEnabled(false);
bar.setDisplayShowHomeEnabled(false);

Upvotes: 1

adsion
adsion

Reputation: 187

Call setDisplayShowHomeEnabled() and setDisplayShowTitleEnabled() on ActionBar, which you get via a call to getActionBar().

Upvotes: 2

vincentzhou
vincentzhou

Reputation: 720

ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);

Or you can just call actionbar.setTitle("")

Upvotes: 25

Related Questions