Search code examples
androidandroid-layoutlistviewnavigation-drawerdrawerlayout

Android DrawerLayout second actionbar does not dim the screen when button is pressed


I have created a program, I have the base nav bar extended like so:

public class navBar extends AppCompatActivity {}

The navbar code itself is too long to include, but it sets a toolbar, and sets a navbar and works great when I use it in most parts of my app.

However, when I try to add another navbar in the extended class it does something odd, when I press the points of interest button to open it and it runs this code:

 public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.POI)
        mDrawerLayout.openDrawer(mDrawerList);
    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

It opens the drawer as requested, but leaves no dimming on the screen. Like so: broken

When I close the screen with the back button/points of interest button for example it lags a bit, dragging the white slowly but closes.

Even worse, when I had opened the drawer with a However, when I use my finger to drag from right to left to open the drawer, it opens and functions perfectly.

functional

Because my map class is rather long as well, I've tried to include only the important code:

 public class Map2 extends navBar {

private Toolbar toolbar;

ActionBarDrawerToggle mDrawerToggle;
private String[] mNavigationDrawerItemTitles;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getLayoutInflater().inflate(R.layout.activity_maptest, frameLayout);
    toolbar = (Toolbar) findViewById(R.id.nav_base_toolbar);
    setSupportActionBar(toolbar);
    toolbar.setNavigationIcon(R.drawable.ic_drawer);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new ActionBarDrawerToggle(
            this,
            mDrawerLayout,
            toolbar,
            R.string.drawer_open,
            R.string.drawer_close
    ) {


        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            mDrawerList.clearChoices();
            super.onDrawerClosed(view);
            //getActionBar().setTitle(mTitle);
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            //getActionBar().setTitle(mDrawerTitle);
        }
    };


    mDrawerLayout.setDrawerListener(mDrawerToggle);


    mNavigationDrawerItemTitles= getResources().getStringArray(R.array.navigation_drawer_items_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.right_drawer);
mNavigationDrawerItemTitles= getResources().getStringArray(R.array.navigation_drawer_items_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.right_drawer);
POIAdapter_without_image adapter2 = new POIAdapter_without_image(this, R.layout.points_of_interest, drawerItem2);

    mDrawerList.setAdapter(adapter2);

    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());



}
    @Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // If the nav drawer is open, hide action items related to the content view
    boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
    menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
    return super.onPrepareOptionsMenu(menu);
}

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    // Sync the toggle state after onRestoreInstanceState has occurred.
    actionBarDrawerToggleChild.syncState();
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_skill_view, menu);
    return true;
}

    public void onBackPressed() {
    if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
        mDrawerLayout.closeDrawer(mDrawerList);
    }
    else
        super.onBackPressed();
}

Edit: Whenever I select a point on the points of interest list, the dragging white line can be seen here moments after the actual drawer has closed: weird_white_bar

The black flash mentioned appears to be android both setting the dim and unsetting the dim as soon as I close the drawer.

This has thoroughly confused me for a few nights now. Thank you all!


Solution

  • In the end, the answer was to call:

    final FrameLayout mapView = (FrameLayout) getLayoutInflater().inflate(R.layout.activity_maptest, frameLayout);
    

    and when I wanted to find anything use

     mDrawerLayout2 = (DrawerLayout) mapView.findViewById(R.id.drawer_layout);
    

    for example.

    it was then necessary to call

    mDrawerLayout2.closeDrawer(GravityCompat.END);
    

    rather than

    mDrawerLayout2.closeDrawer(mDrawerList);
    

    To obtain the needed functionality