Drawer indicator in lollipop play store

后端 未结 5 2005
-上瘾入骨i
-上瘾入骨i 2020-12-24 08:52

I am using a Nexus 7 with the Android 5.0 preview build.

On this page http://developer.android.com/tools/support-library/index.html

I see

5条回答
  •  天命终不由人
    2020-12-24 08:59

    It is very easy.

    Your layout with DrawerLayout looks the same as always. You use android.support.v4.widget.DrawerLayout and create drawers and content area:

    
    
    
    
    
    
    

    Main changes are in your java code. In your Activity, where you use drawer layout, you have to extend it for ActionBarActivity from v7. Then you create variables for DrawerLayout and ActionBarDrawerToggle. Your imports should look like this:

    import android.support.v4.widget.DrawerLayout;
    import android.support.v7.app.ActionBarDrawerToggle;
    import android.support.v7.app.ActionBarActivity;
    

    and then just connect everything. Remember that new drawer layout does not have icon! You just dont pass it where you normally should be. Code for my activity:

    import android.content.res.Configuration;
    import android.os.Bundle;
    import android.support.v4.widget.DrawerLayout;
    import android.support.v7.app.ActionBarDrawerToggle;
    import android.support.v7.app.ActionBarActivity;
    import android.view.MenuItem;
    
    public class MainActivity extends ActionBarActivity {
    
        DrawerLayout drawerLayout;
        ActionBarDrawerToggle drawerToggle;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
            drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.app_name, R.string.app_name) {};
    
            drawerLayout.setDrawerListener(drawerToggle);
    
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setHomeButtonEnabled(true);
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            if (drawerToggle.onOptionsItemSelected(item)) {
                return true;
            }
            return super.onOptionsItemSelected(item);
        }
    
        @Override
        protected void onPostCreate(Bundle savedInstanceState) {
            super.onPostCreate(savedInstanceState);
            drawerToggle.syncState();
        }
    
        @Override
        public void onConfigurationChanged(Configuration newConfig) {
            super.onConfigurationChanged(newConfig);
            drawerToggle.onConfigurationChanged(newConfig);
        }
    
    }
    

    And it should work.

提交回复
热议问题