简体   繁体   中英

How to remove elevation (drop shadow) from a DrawerLayout in Android Studio?

How can I remove the elevation (drop shadow) from a DrawerLayout in Android Studio? I've looked everywhere, and tried adding app:elevation="0dp" and android:elevation="0dp" to my DrawerLayout xml, but it doesn't work.

I even tried adding setElevation(0f) to my MainActivity , but that didn't work either.

What am I doing wrong? Thanks.

(PS The project's base API is 16... I tried changing it to 21, but that didn't make any difference.)

Here's my onCreate:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "MUHAHA BURP BARF BARF WHAHAHA", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

        DrawerLayout drawer = (DrawerLayout) findViewById(drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);

        populateListView();
    }

Solved it. Turns out I was trying to remove the elevation from drawer_layout when I should've been removing it from drawer . Putting drawer.setDrawerElevation(0f); in my MainActivity fixed the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM