I'm kind of new to Android. I added menu icons into my application. Here is my code.
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="1"
android:showAsAction="never" />
<item
android:id="@+id/action_example"
android:title="Logout"
android:orderInCategory="2"
android:showAsAction="withText|ifRoom" />
<item
android:id="@+id/addLoc"
android:title=""
android:orderInCategory="1"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_location"
android:onClick="gotoLocation"/>
<item
android:id="@+id/dealsPic"
android:title=""
android:orderInCategory="2"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_deals"
android:onClick="doThis"/>
<item
android:id="@+id/profPicture"
android:title=""
android:orderInCategory="3"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_prof"
android:onClick="userProfile"
/>
<item
android:id="@+id/namePerson"
android:title="Nathalia Smith"
android:orderInCategory="4"
app:showAsAction="ifRoom"
android:onClick="userProfile"/>
</menu>
After added theses menu icons in to my Action Bar menu icons appeared. but, when I Expand my Navigation drawer, icons just disappear and when I close it icons appear.
What I need is to appear these icons whenever the drawer is opened.
Here is my onCreate.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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));
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#FFA500"))); // change the color of header
mTitle = mDrawerTitle = getTitle();
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
// enabling action bar app icon and behaving it as toggle button
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,R.drawable.ic_menu, R.string.app_name,R.string.app_name)
{
public void onDrawerClosed(View view) {
getSupportActionBar().setTitle(mTitle);
// calling onPrepareOptionsMenu() to show action bar icons
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
getSupportActionBar().setTitle(mDrawerTitle);
// calling onPrepareOptionsMenu() to hide action bar icons
invalidateOptionsMenu(); }
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
getSupportActionBar().setIcon(R.drawable.ic_deals);
}
Here is my onDrawerClosed and onDrawerOpened
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,R.drawable.ic_menu, R.string.app_name,R.string.app_name)
{
public void onDrawerClosed(View view) {
getSupportActionBar().setTitle(mTitle);
// calling onPrepareOptionsMenu() to show action bar icons
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
getSupportActionBar().setTitle(mDrawerTitle);
// calling onPrepareOptionsMenu() to hide action bar icons
invalidateOptionsMenu(); }
};
hat I need is to appear these icons whenever the drawer is opened. Someone please help.
Thanks in advance. :)