android.support.v7.app.ActionBarDrawerToggle Java Examples

The following examples show how to use android.support.v7.app.ActionBarDrawerToggle. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java    From android-md-core with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  ButterKnife.bind(this);

  boolean isFitSystemWindows = ViewCompat.getFitsSystemWindows(vDrawerLayout);
  if (isFitSystemWindows) {
    MdCompat.enableTranslucentStatus(this);
  }

  setSupportActionBar(vToolbar);

  mActionBarDrawerToggle = new ActionBarDrawerToggle(this, vDrawerLayout, vToolbar, R.string.text_open, R.string.text_close);
  vDrawerLayout.addDrawerListener(mActionBarDrawerToggle);
  mActionBarDrawerToggle.syncState();

  vNavigationViewLeft.setNavigationItemSelectedListener(item -> onNavigationItemSelected(GravityCompat.START, item));
  vNavigationViewRight.setNavigationItemSelectedListener(item -> onNavigationItemSelected(GravityCompat.END, item));

  ImageView leftLogo = (ImageView) vNavigationViewLeft.getHeaderView(0).findViewById(R.id.google_logo);
  MdCompat.supportDrawableTint(this, leftLogo.getDrawable(), MdCompat.Palette.BACKGROUND);
  ImageView rightLogo = (ImageView) vNavigationViewRight.getHeaderView(0).findViewById(R.id.google_logo);
  MdCompat.supportDrawableTint(this, rightLogo.getDrawable(), MdCompat.Palette.BACKGROUND);
}
 
Example #2
Source File: ColorPaletteActivity.java    From MaterialDesignColorPalette with Apache License 2.0 6 votes vote down vote up
private void setupNavigationDrawer(Toolbar toolbar) {
    mDrawerList.setAdapter(new DrawerAdapter(this, mColorList));
    mDrawerList.setOnItemClickListener(drawerClickListener);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
            toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            doDrawerClosed();
        }

        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            doDrawerOpened();
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
}
 
Example #3
Source File: MainActivity.java    From miappstore with Apache License 2.0 6 votes vote down vote up
@Override
protected void initToolBar() {
    super.initToolBar();
    view = View.inflate(this, R.layout.activity_main, null);
    toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    drawerLayout = (DrawerLayout) view.findViewById(R.id.drawer_layout);
    toolbar.setBackgroundColor(getResources().getColor(R.color.light_toolbar));
    toolbar.setTitle("应用商店");
    toolbar.setLogo(R.mipmap.logo);//设置Logo
    setSupportActionBar(toolbar);
    ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(
            this, drawerLayout, toolbar, R.string.app_name, R.string.app_name
    );
    drawerLayout.setDrawerListener(drawerToggle);
    drawerToggle.syncState();
}
 
Example #4
Source File: MainActivity.java    From android-atleap with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);


    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.activity_main_drawer_open, R.string.activity_main_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    mNavigationView.setNavigationItemSelectedListener(this);
}
 
Example #5
Source File: GeometryDescartesActivity.java    From ncalc with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_geometry_descartes);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.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);

    mPager = (ViewPager) findViewById(R.id.viewpager);
    mPager.setOffscreenPageLimit(mCount);
    PagerApdater mAdapter = new PagerApdater(getSupportFragmentManager(), this);
    mPager.setAdapter(mAdapter);
    mPager.addOnPageChangeListener(this);

    mTab = (TabLayout) findViewById(R.id.tab);
    mTab.setupWithViewPager(mPager, true);
}
 
Example #6
Source File: SystemEquationActivity.java    From ncalc with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_linear_system);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    setTitle(R.string.solve_system_equation);

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

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

    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    viewPager.setOffscreenPageLimit(2);
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tab);

    SectionPagerAdapter adapter = new SectionPagerAdapter(getSupportFragmentManager(), this);
    viewPager.setAdapter(adapter);
    tabLayout.setupWithViewPager(viewPager);
}
 
Example #7
Source File: MainActivity.java    From Girls with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, mToolbar, 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);
    navigationView.setCheckedItem(R.id.nav_new);
    changeFragment(new NewFragment());
}
 
Example #8
Source File: AbstractBrowserActivity.java    From SimpleExplorer with GNU General Public License v3.0 6 votes vote down vote up
private void setupDrawer() {
    mDrawer = (ListView) findViewById(R.id.left_drawer);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar,
            R.string.drawer_open, R.string.drawer_close) {
        @Override
        public void onDrawerOpened(View drawerView) {
            supportInvalidateOptionsMenu();
        }

        @Override
        public void onDrawerClosed(View view) {
            supportInvalidateOptionsMenu();
        }
    };

    mDrawerLayout.addDrawerListener(mDrawerToggle);
}
 
Example #9
Source File: MainActivity.java    From fontster with Apache License 2.0 6 votes vote down vote up
@Override protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  setToolbarTitle(getString(R.string.app_name));

  if (!BuildConfig.DEBUG) initializeAd(mAdView);

  mDrawerToggle = new ActionBarDrawerToggle(
      this, mDrawerLayout, mToolbar, R.string.drawer_open, R.string.drawer_close);

  setupDrawerContent(mNavigationView);
  mDrawerLayout.setDrawerListener(mDrawerToggle);

  mFragmentManager = getSupportFragmentManager();
  mFontListFragment = new FontListFragment();
  mBackupRestoreFragment = new BackupRestoreFragment();

  swapFragment(mFontListFragment);
}
 
Example #10
Source File: BaseActivity.java    From good-weather with GNU General Public License v3.0 6 votes vote down vote up
private void setupNavDrawer() {
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    if (mDrawerLayout == null) {
        return;
    }
    mDrawerToggle = new ActionBarDrawerToggle(this,
                                              mDrawerLayout,
                                              mToolbar,
                                              R.string.navigation_drawer_open,
                                              R.string.navigation_drawer_close);
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    mDrawerToggle.syncState();

    if (mToolbar != null) {
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mDrawerLayout.openDrawer(GravityCompat.START);
            }
        });
    }

    configureNavView();
}
 
Example #11
Source File: MainActivity.java    From text_converter with GNU General Public License v3.0 6 votes vote down vote up
private void bindView() {
    mCoordinatorLayout = findViewById(R.id.container);
    String text = getTextFromAnotherApp();

    ViewPager viewPager = findViewById(R.id.view_pager);
    PagerAdapter adapter = getPageAdapter(text);
    viewPager.setOffscreenPageLimit(adapter.getCount());
    viewPager.setAdapter(adapter);
    viewPager.addOnPageChangeListener(this);
    ((SmartTabLayout) findViewById(R.id.tab_layout)).setViewPager(viewPager);

    //attach listener hide/show keyboard
    KeyBoardEventListener keyBoardEventListener = new KeyBoardEventListener(this);
    mCoordinatorLayout.getViewTreeObserver().addOnGlobalLayoutListener(keyBoardEventListener);

    mDrawerLayout = findViewById(R.id.drawer_layout);
    mNavigationView = findViewById(R.id.nav_view);
    ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
            mToolbar, R.string.desc_open_drawer, R.string.desc_close_drawer);
    mDrawerLayout.addDrawerListener(drawerToggle);
    drawerToggle.syncState();
    mNavigationView.setNavigationItemSelectedListener(this);
}
 
Example #12
Source File: ProjectManagerActivity.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void setupToolbar() {
    //setup action bar
    toolbar = findViewById(R.id.toolbar);
    appBarLayout = findViewById(R.id.app_bar);

    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayShowTitleEnabled(false);
    }

    if (getResources().getConfiguration().orientation == ORIENTATION_PORTRAIT) {
        ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar,
                R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        // Set the drawer toggle as the DrawerListener
        mDrawerLayout.setDrawerListener(mDrawerToggle);
        mDrawerToggle.syncState();
    }

    //attach listener hide/show keyboard
    mKeyBoardListener = new KeyBoardEventListener(this);
    mDrawerLayout.getViewTreeObserver().addOnGlobalLayoutListener(mKeyBoardListener);
}
 
Example #13
Source File: MainActivity.java    From AndroidBarUtils with Apache License 2.0 6 votes vote down vote up
private void initView() {
        drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawerLayout.addDrawerListener(toggle);
        toggle.syncState();
        //修复DrawerLayout 在4.4 下出现白条的问题
//        AndroidBarUtils.setTranslucentDrawerLayout(drawerLayout);

        navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        //适配NavigationView 刘海屏
        AndroidBarUtils.setBarPaddingTop(this, navigationView.getHeaderView(0));

        fab = (FloatingActionButton) findViewById(R.id.fab);
        switchCompat = (SwitchCompat) findViewById(R.id.main_sc_mode);
        sb_alpha = (AppCompatSeekBar) findViewById(R.id.main_sb_alpha);
        sb_red = (AppCompatSeekBar) findViewById(R.id.main_sb_red);
        sb_green = (AppCompatSeekBar) findViewById(R.id.main_sb_green);
        sb_blue = (AppCompatSeekBar) findViewById(R.id.main_sb_blue);
        sb_alpha.setProgress(alpha);
        sb_red.setProgress(red);
        sb_green.setProgress(green);
        sb_blue.setProgress(blue);
    }
 
Example #14
Source File: MainActivity.java    From STUer-client with MIT License 6 votes vote down vote up
private void initToolbar() {
    mToolbar.setTitle(getString(R.string.carpool));
    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.hello_world, R.string.hello_world);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mToolbar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // 双击Toolbar滚回顶部
            long currentTimeMillis = System.currentTimeMillis();
            if (currentTimeMillis - mToolbarClickLastTime >= 2000) {
                mToolbarClickLastTime = System.currentTimeMillis();
            } else {
                currentFragment.smoothToTop();
            }
        }
    });
}
 
Example #15
Source File: MainActivity.java    From ShapedNavigationView with MIT License 6 votes vote down vote up
@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, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.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 = (ShapedNavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}
 
Example #16
Source File: BaseActivity.java    From privacy-friendly-pedometer with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (getSupportActionBar() == null) {
        setSupportActionBar(toolbar);
    }

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, mDrawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    mDrawerLayout.addDrawerListener(toggle);
    toggle.syncState();

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

    selectNavigationItem(getNavigationDrawerID());

    View mainContent = findViewById(R.id.main_content);
    if (mainContent != null) {
        mainContent.setAlpha(0);
        mainContent.animate().alpha(1).setDuration(MAIN_CONTENT_FADEIN_DURATION);
    }
}
 
Example #17
Source File: OverScrollDemoActivity.java    From elasticity with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_overscroll_demo);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(R.string.recycler_view_demo_title);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.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.drawer_nav);
    navigationView.setNavigationItemSelectedListener(this);

    if (savedInstanceState == null) {
        getFragmentManager().beginTransaction()
                .add(R.id.fragment_placeholder, new RecyclerViewDemoFragment())
                .commit();
    }
}
 
Example #18
Source File: BaseActivity.java    From privacy-friendly-passwordgenerator with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if(getSupportActionBar() == null) {
        setSupportActionBar(toolbar);
    }

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, mDrawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    mDrawerLayout.addDrawerListener(toggle);
    toggle.syncState();

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

    selectNavigationItem(getNavigationDrawerID());

    View mainContent = findViewById(R.id.main_content);
    if (mainContent != null) {
        mainContent.setAlpha(0);
        mainContent.animate().alpha(1).setDuration(MAIN_CONTENT_FADEIN_DURATION);
    }
}
 
Example #19
Source File: BaseDrawerLayoutActivity.java    From ZfsoftCampusAssit with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (this.getNavigationItemSelectedListener() != null)
        this.mNavigationView.setNavigationItemSelectedListener(this.getNavigationItemSelectedListener());
    hideVerticalScrollBar();
    this.mDrawerLayout.setDrawerListener(new DrawerStateListener());

    // 初始化MenuItems
    this.mMenuItems = new HashMap<>();
    int[] menuItemIds = this.getMenuItemIds();
    if (menuItemIds.length > 0) {
        for (int id : menuItemIds) {
            MenuItem menuItem = this.mNavigationView.getMenu().findItem(id);
            if (menuItem != null) this.mMenuItems.put(id, menuItem);
        }
    }

    this.mDrawerToggle = new ActionBarDrawerToggle(
            this,
            this.mDrawerLayout,
            R.string.app_menu,
            R.string.app_name
    );

}
 
Example #20
Source File: MainActivity.java    From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

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

    NavigationView navigationView = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}
 
Example #21
Source File: HomeActivity.java    From Bus-Tracking-Parent with GNU General Public License v3.0 5 votes vote down vote up
private void setDrawerLayout() {
    //drawerLayout= (DrawerLayout) findViewById(R.id.drawable_layout);
    actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open, R.string.drawer_close);

    drawerLayout.addDrawerListener(actionBarDrawerToggle);
    //This is necessary to change the icon of the Drawer Toggle upon state change.
    actionBarDrawerToggle.syncState();
}
 
Example #22
Source File: MainActivity.java    From TabbedCoordinatorLayout with Apache License 2.0 5 votes vote down vote up
private void setupDrawer() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

}
 
Example #23
Source File: MainActivity.java    From GoogleVR with Apache License 2.0 5 votes vote down vote up
private void initActionBar() {
	ActionBar actionBar = getSupportActionBar();
	actionBar.setDisplayHomeAsUpEnabled(true);
	mToggle = new ActionBarDrawerToggle(this,drawerLayout, R.string.open,R.string.close);
	mToggle.syncState();
	drawerLayout.addDrawerListener(mToggle);
}
 
Example #24
Source File: HomeActivity.java    From lockit with Apache License 2.0 5 votes vote down vote up
@AfterViews
void setupNavigationView() {
    mDrawerToggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.app_name, R.string.app_name);
    mDrawerToggle.setDrawerIndicatorEnabled(true);
    drawer.setDrawerListener(mDrawerToggle);
    navigation.setNavigationItemSelectedListener(this::navigationItemSelected);
    navigation.getMenu().getItem(0).setChecked(true);
}
 
Example #25
Source File: MainActivity.java    From photosearcher with Apache License 2.0 5 votes vote down vote up
private void setupRightDrawer() {
    mTabListAdapter = new TabListAdapter(
            mTimelineManager,
            this,
            this::onDeleteQuery,
            this::onMoveTab,
            this::onTabSelect);

    mTabListTouchCallback = new TabListTouchHelperCallback(mTabListAdapter);

    mTabList.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    mTabList.setHasFixedSize(true);
    mTabList.setAdapter(mTabListAdapter);

    mItemTouchHelper = new ItemTouchHelper(mTabListTouchCallback);
    mItemTouchHelper.attachToRecyclerView(mTabList);

    mDrawerToggle = new ActionBarDrawerToggle(
            this,
            mDrawerLayout,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close) {

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            UIUtil.hideKeyboard(MainActivity.this);

            int newPosition = mCurrentTabPosition;
            mDrawerToggle.syncState();

            mHandler.postDelayed(() -> mViewPager.setCurrentItem(newPosition, false), 100);
        }
    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);
}
 
Example #26
Source File: MainActivity.java    From XiaoxiaZhihu with Apache License 2.0 5 votes vote down vote up
private void init() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    int close = R.string.navigation_drawer_close;
    int open = R.string.navigation_drawer_open;
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, open, close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();
}
 
Example #27
Source File: MainActivity.java    From Messenger-Android-XML-Template with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    setupToolbar(R.id.toolbar, "Messages");

    FragmentTransaction ft;
    FragmentHome fragmentHome = new FragmentHome();
    ft = getSupportFragmentManager().beginTransaction();
    ft.add(R.id.frameLayout, fragmentHome).commit();

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

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

    navigationViewBottom = (NavigationView) findViewById(R.id.nav_view_bottom);
    navigationViewBottom.setNavigationItemSelectedListener(this);


    chats =(TextView) MenuItemCompat.getActionView(navigationView.getMenu().
            findItem(R.id.nav_chats));
    initializeCountDrawer();

}
 
Example #28
Source File: MainActivity.java    From diycode with Apache License 2.0 5 votes vote down vote up
private void initMenu(ViewHolder holder) {
    Toolbar toolbar = holder.get(R.id.toolbar);
    toolbar.setLogo(R.mipmap.logo_actionbar);
    toolbar.setTitle("");
    DrawerLayout drawer = holder.get(R.id.drawer_layout);
    setSupportActionBar(toolbar);
    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);

    // 双击 666
    final GestureDetector detector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            quickToTop();   // 快速返回头部
            return super.onDoubleTap(e);
        }
    });

    toolbar.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            detector.onTouchEvent(event);
            return false;
        }
    });

    toolbar.setOnClickListener(this);

    holder.setOnClickListener(this, R.id.fab);

    loadMenuData();
}
 
Example #29
Source File: Main.java    From kute with Apache License 2.0 5 votes vote down vote up
/*********************** Overrides ************************/
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    route_request_number = (TextView) findViewById(R.id.numberRouteRequests);
    route_request=(ImageButton)findViewById(R.id.routeRequests);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    /****************************** Drawer Layout Setup ************************/
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.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);
    /******************************* End Of Drawer Setup **************************/
    /********************* Load Home Base Fragment**********/
   setupHomeFragment();
    navigationView.setCheckedItem(R.id.Home);
    final SharedPreferences pref = getApplicationContext().getSharedPreferences("user_credentials", 0); // 0 - for private mode
    Log.d("SharedPreference", pref.getString("Profile_Image", null));


}
 
Example #30
Source File: MainActivity.java    From Muslim-Athkar-Islamic-Reminders with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    initializeAll();
    playSound();//this method will play opening sound
    this.startService(mServiceIntent);//start IntentService for fetch data from online server

    final DrawerLayout drawer = findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);

    toggle.syncState();

    if (savedData.getIsAppFirstTimeOpen()){
        fragment = new Settings();
        changeSelectedNavBg(findViewById(R.id.navSettingRl));
    }
    transaction.add(R.id.containerMain,fragment);
    transaction.commit();

}