I am currently trying to add a custom layout to my action bar but keep running into a null pointer exception and can't figure out a way around it.
Here is my onCreateOptionsMenu
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
ActionBar mActionBar = getActionBar();
LayoutInflater mInflater = LayoutInflater.from(this);
View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);
TextView mTitleTextView = (TextView) mCustomView.findViewById(R.id.menuText);
mTitleTextView.setText("Insert Title Here");
ImageButton imageButton = (ImageButton) mCustomView.findViewById(R.id.menuPlusButton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Start New Course", Toast.LENGTH_LONG).show();
}
});
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowTitleEnabled(false);
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);
return super.onCreateOptionsMenu(menu);
}
The error seems to occur at mActionBar.setDisplayShowHomeEnabled(false) which indicates that ActionBar mActionBar = getActionBar() is returning null, and I cant figure out why. I extend AppCompatActivity and am running min API 7.
Thanks in advance.