1

I have a class extending ListActivity and I am trying to hide the default TitleBar (I think it's called ActionBar) using the code below. It works on a regular activity, but not on the ListActivity. How do I accomplish the same in this scenario?

public class MyClass extends ListActivity{
    @Override
    public void onCreate(Bundle b) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(b);
        // Tried Window.FEATURE_NO_TITLE here as well
        setContentView(R.layout.activity_myclass);
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }
}

The result is a NullPointerException. The full error stack trace is here if you need it: http://pastebin.com/VLR5dE8m

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Dzhuneyt
  • 8,437
  • 14
  • 64
  • 118
  • Can you post the stacktrace here? I'm behind a corporate proxy.. :| – Enrichman Nov 08 '12 at 11:04
  • try **Window.FEATURE** after **setContentView()**. Just a thought. – Sahil Mahajan Mj Nov 08 '12 at 11:05
  • call requestWindowFeature(Window.FEATURE_NO_TITLE) after super.onCreate() and setContentView()..... set the window first then set No title bar option. – drulabs Nov 08 '12 at 11:06
  • OR you can also Write this "android:theme="@android:style/Theme.NoTitleBar" in manifest under activity tag – drulabs Nov 08 '12 at 11:08
  • what's line 50 ? getActionBar seems null to me – njzk2 Nov 08 '12 at 11:13
  • possible duplicate of [When does android's ListActivity class call setContentView()?](http://stackoverflow.com/questions/6903487/when-does-androids-listactivity-class-call-setcontentview) – user Nov 08 '12 at 11:13

4 Answers4

1

to disable Titltbar,, use this code in your manifest file ,it will help you.

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

Shivansh Saxena
  • 204
  • 2
  • 8
0

I think You should not use requestWindowFeature() if you are using ActionBar. You can hide title of ActionBar with this:

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

http://developer.android.com/reference/android/app/ActionBar.html#setDisplayShowTitleEnabled(boolean)

traninho
  • 1,533
  • 12
  • 19
  • that's useless since it will just show an icon but without the text title next to it. what you *also* want is `actionBar.setDisplayShowHomeEnabled(false);` – Someone Somewhere Nov 07 '13 at 07:05
0

To remove the actionbar: getActionBar().hide(). Also see this answer: How to disable action bar permanently

Community
  • 1
  • 1
RufusInZen
  • 2,119
  • 1
  • 19
  • 26
-1

It seems like the NullPointerException is generated by getActionBar(). Removing the following line from the code fixed the issue.

getActionBar().setDisplayHomeAsUpEnabled(true);

The final (working) code:

public class MyClass extends ListActivity{
    @Override
    public void onCreate(Bundle b) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(b);
        setContentView(R.layout.activity_myclass);
     }
}

Note that requestWindowFeature must be called before calling the super class and setContentView.

Dzhuneyt
  • 8,437
  • 14
  • 64
  • 118