Java Code Examples for android.support.v7.app.ActionBarDrawerToggle

The following examples show how to use android.support.v7.app.ActionBarDrawerToggle. These examples are extracted from open source projects. 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 Project: android-atleap   Author: blandware   File: MainActivity.java    License: 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 #2
Source Project: MaterialDesignColorPalette   Author: HozakaN   File: ColorPaletteActivity.java    License: 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 Project: good-weather   Author: qqq3   File: BaseActivity.java    License: 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 #4
Source Project: java-n-IDE-for-Android   Author: shenghuntianlang   File: ProjectManagerActivity.java    License: 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 #5
Source Project: AndroidBarUtils   Author: yy1300326388   File: MainActivity.java    License: 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 #6
Source Project: ShapedNavigationView   Author: naseemali925   File: MainActivity.java    License: 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 #7
Source Project: elasticity   Author: XanderWang   File: OverScrollDemoActivity.java    License: 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 #8
Source Project: Android-Developer-Fundamentals-Version-2   Author: MahakAggarwal   File: MainActivity.java    License: 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 #9
Source Project: ZfsoftCampusAssit   Author: hjw541988478   File: BaseDrawerLayoutActivity.java    License: 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 #10
@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 #11
Source Project: privacy-friendly-pedometer   Author: SecUSo   File: BaseActivity.java    License: 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 #12
Source Project: STUer-client   Author: leelit   File: MainActivity.java    License: 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 #13
Source Project: text_converter   Author: tranleduy2000   File: MainActivity.java    License: 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 #14
Source Project: Girls   Author: flyou   File: MainActivity.java    License: 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 #15
Source Project: fontster   Author: ItsPriyesh   File: MainActivity.java    License: 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 #16
Source Project: SimpleExplorer   Author: DF1E   File: AbstractBrowserActivity.java    License: 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 #17
Source Project: android-md-core   Author: henrytao-me   File: MainActivity.java    License: 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 #18
Source Project: ncalc   Author: tranleduy2000   File: SystemEquationActivity.java    License: 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 #19
Source Project: ncalc   Author: tranleduy2000   File: GeometryDescartesActivity.java    License: 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 #20
Source Project: miappstore   Author: shipan2012   File: MainActivity.java    License: 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 #21
Source Project: XiaoxiaZhihu   Author: LiushuiXiaoxia   File: MainActivity.java    License: 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 #22
Source Project: android-player   Author: geftimov   File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void initDrawerLayout() {
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    final ActionBar supportActionBar = getSupportActionBar();
    final DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.activityMainDrawerLayout);
    final ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.abc_toolbar_collapse_description,
            R.string.abc_toolbar_collapse_description);
    drawerToggle.setDrawerIndicatorEnabled(true);
    supportActionBar.setDisplayHomeAsUpEnabled(true);
    supportActionBar.setHomeButtonEnabled(true);
    supportActionBar.setDisplayShowTitleEnabled(false);
    drawerToggle.syncState();
    drawerLayout.setDrawerListener(drawerToggle);
}
 
Example #23
Source Project: RHub   Author: apptik   File: MainActivity.java    License: Apache License 2.0 5 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);
    shield = Shield.Inst.get();
    TextView tv1 = (TextView) findViewById(R.id.txt1);
    compositeSubscription.add(shield.sensorData().subscribe(new Comp1()));
    compositeSubscription.add(shield.sensorData().subscribe(new Comp2(tv1)));
    compositeSubscription.add(shield.actionEvents().subscribe(new ActionHandler()));

    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 navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}
 
Example #24
Source Project: AwesomeValidation   Author: thyrlian   File: DemoActivity.java    License: MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_demo);
    mViewSuccess = (LinearLayout) findViewById(R.id.container_success);
    mScrollView = (ScrollView) findViewById(R.id.scroll_view);
    mViewContainerEditText = findViewById(R.id.container_edit_text);
    mViewContainerTextInputLayout = findViewById(R.id.container_text_input_layout);
    mStyles = getResources().getStringArray(R.array.styles);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
    }
    setupSpinner();
    // AwesomeValidation.disableAutoFocusOnFirstFailure();
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.app_name, R.string.app_name);
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mStyles));
    mDrawerList.setOnItemClickListener(mDrawerItemClickListener);
    mDrawerItemClickListener.selectItem(mPosition);
}
 
Example #25
Source Project: Fishing   Author: Jude95   File: MainActivity.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity_main);
    SwipeBackHelper.getCurrentPage(this).setSwipeBackEnable(false);
    ButterKnife.inject(this);
    mDrawerToggle = new ActionBarDrawerToggle(this
            , drawerLayout
            , (Toolbar) findViewById(R.id.toolbar)
            , 0
            , 0);
    drawerLayout.post(() -> mDrawerToggle.syncState());
    drawerLayout.setDrawerListener(mDrawerToggle);
    init();
}
 
Example #26
Source Project: Paginate   Author: MarkoMilos   File: BaseActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void setupBasicUI() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayShowTitleEnabled(false);

    DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_closed);
    drawerLayout.setDrawerListener(drawerToggle);
    drawerToggle.syncState();
}
 
Example #27
Source Project: rox-android   Author: dan-zx   File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void setupNavigationDrawer() {
    drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close);
    drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);
    drawerLayout.setStatusBarBackground(R.color.primary_dark);
    drawerLayout.setDrawerListener(drawerToggle);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    setupDrawerMenu();
}
 
Example #28
Source Project: AndroidChromium   Author: JackyAndroid   File: SelectionToolbar.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set up ActionBarDrawerToggle, a.k.a. hamburger button.
 */
private void initActionBarDrawerToggle() {
    // Sadly, the only way to set correct toolbar button listener for ActionBarDrawerToggle
    // is constructing, so we will need to construct every time we re-show this button.
    mActionBarDrawerToggle = new ActionBarDrawerToggle((Activity) getContext(),
            mDrawerLayout, this,
            R.string.accessibility_drawer_toggle_btn_open,
            R.string.accessibility_drawer_toggle_btn_close);
    mDrawerLayout.addDrawerListener(mActionBarDrawerToggle);
    mActionBarDrawerToggle.syncState();
}
 
Example #29
Source Project: WanAndroid   Author: CoderLengary   File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void initViews() {
    mToolbar = findViewById(R.id.toolBar);
    setSupportActionBar(mToolbar);
    mNavigationView = findViewById(R.id.nav_view);
    mDrawerLayout = findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar
            , R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    mDrawerLayout.addDrawerListener(toggle);
    toggle.syncState();
    mNavigationView.setNavigationItemSelectedListener(this);
    mBottomNavigationView = findViewById(R.id.bottom_navigation_view);
    mTextUserIcon = mNavigationView.getHeaderView(0).findViewById(R.id.text_user_icon);
    mTextUserName = mNavigationView.getHeaderView(0).findViewById(R.id.text_user_name);

}
 
Example #30
Source Project: ZhihuDaily   Author: nyakokishi   File: MainActivity.java    License: MIT License 5 votes vote down vote up
@Override
protected void initViews(Bundle savedInstanceState) {
    setSupportActionBar(mToolbar);

    if (isColorTheme) {
        mToolbar.setBackgroundColor(getResources().getColor(R.color.blue));
        mRefreshLayout.setBackgroundColor(getResources().getColor(R.color.home_background));
    } else {
        if (TextUtils.isEmpty(background)) {
            mLinearLayout.setBackground(getResources().getDrawable(R.drawable.main_background));
        } else {
            updateBackground();
        }
    }

    ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar
            , R.string.app_name, R.string.app_name);
    mDrawerLayout.setDrawerListener(drawerToggle);
    drawerToggle.syncState();

    initFragment();

    mRefreshLayout.setColorSchemeResources(android.R.color.holo_red_light
            , android.R.color.holo_orange_light, android.R.color.holo_green_light
            , android.R.color.holo_blue_bright);
    mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            currentFragment.loadData();
            mRefreshLayout.setRefreshing(false);
        }
    });

    if (isAutoLogin) {
        autoLogin();
    }
}