I'm attempting to use a navigation drawer and an action bar in my application.
The top leftmost button in the action bar opens and closes the drawer, and does not have a title in the drawer closed state. But when the drawer is opened, the title reappears. The title is the project name. I'm looking to remove this title from every scenario. In the code below you can see I've tried to set it again inside drawer open and close
private NavigationDrawerFragment mNavigationDrawerFragment;
private ActionBarDrawerToggle mDrawerToggle;
private DrawerLayout mDrawerLayout;
/**
* Used to store the last screen title. For use in {@link #restoreActionBar()}.
*/
private CharSequence mTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
setTitle("");
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setIcon(R.drawable.plus);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
// Set up the drawer.
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_closed)
{
/*
* Called when a drawer has settled in a completely closed state
*/
public void onDrawerClosed(View view)
{
Log.d("drawerToggle", "Drawer closed");
super.onDrawerClosed(view);
setTitle("");
//getActionBar().setTitle(R.string.app_name);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(false);
invalidateOptionsMenu(); //Creates call to onPrepareOptionsMenu()
}
/*
* Called when a drawer has settled in a completely open state
*/
public void onDrawerOpened(View drawerView)
{
super.onDrawerOpened(drawerView);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(false);
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
Also the three horizontal lines that change when the drawer is open / closed, what's the best way to just completely remove these lines (but keep the main icon)? At the moment I've just set ic_drawer to a transparent image.
Also below is my code that changes the menu when the drawer is open / closed. It seems to work, but is this the best way to go about doing this?
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
if (!mNavigationDrawerFragment.isDrawerOpen()) {
inflater.inflate(R.menu.main, menu);
//restoreActionBar();
System.out.println("inhere");
//return true;
//return super.onCreateOptionsMenu(menu);
}
else
inflater.inflate(R.menu.close_left_drawer, menu);
return super.onCreateOptionsMenu(menu);
}
Thanks.