Example usage for android.view MenuItem setChecked

List of usage examples for android.view MenuItem setChecked

Introduction

In this page you can find the example usage for android.view MenuItem setChecked.

Prototype

public MenuItem setChecked(boolean checked);

Source Link

Document

Control whether this item is shown with a check mark.

Usage

From source file:com.dj.hacktor.nshiddenlayout.MainActivity.java

private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override//from ww w  .  j  a  v  a  2 s . co  m
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            mDrawerLayout.closeDrawers();
            menuItem.setChecked(true);
            getSupportActionBar().setTitle(menuItem.getTitle());
            return true;
        }
    });
}

From source file:com.support.android.designlibdemo.MainActivity.java

private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override/*w w  w.  j  a va2  s .  c om*/
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            menuItem.setChecked(true);
            mDrawerLayout.closeDrawers();
            return true;
        }
    });
}

From source file:csci4176.toptentoday.MainActivity.java

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

    //setup toolbar
    Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);//from w ww  .  jav  a2s .c o m
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    //setup drawer and hamburger icon
    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawer, mToolbar,
            R.string.drawer_open, R.string.drawer_close);
    mDrawer.addDrawerListener(mDrawerToggle);
    mDrawerToggle.syncState();

    //create viewpager tabs
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
    tabLayout.addTab(tabLayout.newTab().setText("Articles"));
    tabLayout.addTab(tabLayout.newTab().setText("Movies"));
    tabLayout.addTab(tabLayout.newTab().setText("Shows"));
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

    //add viewpager, set paging limit and attach custom adapter
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    mViewPager.setOffscreenPageLimit(2);
    adapter = new PagerAdapter(getSupportFragmentManager(), tabLayout.getTabCount());
    mViewPager.setAdapter(adapter);
    //attach tabs to viewpager
    tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            mViewPager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
        }
    });

    //setup drawer menu onItemSelected
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            menuItem.setChecked(true);
            onNavItemSelected(menuItem);
            return true;
        }
    });
}

From source file:com.emotion.emotioncontrol.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (!mNavigationDrawerFragment.isDrawerOpen()) {
        // Only show items in the action bar relevant to this screen
        // if the drawer is not showing. Otherwise, let the drawer
        // decide what to show in the action bar.
        getMenuInflater().inflate(R.menu.main, menu);
        restoreActionBar();/* w  w w  .j a v  a 2s  . com*/

        MenuItem showDrawerIcon = menu.findItem(R.id.action_show_drawer_icon);

        showDrawerIcon.setChecked(isLauncherIconEnabled());

        return true;
    }
    return super.onCreateOptionsMenu(menu);
}

From source file:edu.dartmouth.cs.stressmeter.psm.MainActivity.java

/**
 * Handles clicks on the navigation menu.
 *//* w ww .  jav a 2 s  .com*/
@Override
public boolean onNavigationItemSelected(final MenuItem menuItem) {
    // update highlighted item in the navigation menu
    menuItem.setChecked(true);
    mNavItemId = menuItem.getItemId();

    // allow some time after closing the drawer before performing real navigation
    // so the user can see what is happening
    mDrawerLayout.closeDrawer(GravityCompat.START);
    mDrawerActionHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            navigate(menuItem.getItemId());
        }
    }, DRAWER_CLOSE_DELAY_MS);
    return true;
}

From source file:com.github.michalbednarski.intentslab.StartActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem interceptionOption = menu.findItem(R.id.interception);
    interceptionOption.setChecked(getPackageManager().getComponentEnabledSetting(
            mInterceptActivityComponentName) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
    Utils.updateLegacyCheckedIcon(interceptionOption);
    return true;//from   www. j  a  va  2  s . c  o  m
}

From source file:ca.rmen.android.scrumchatter.main.TeamNavigationMenu.java

void load() {
    Log.v(TAG, "load");
    mTeams.getAllTeams().subscribe(teamsData -> {
        // Update the navigation view.
        SubMenu teamsMenu = mNavigationMenu.findItem(R.id.teams_list).getSubMenu();
        teamsMenu.clear();/*from   ww w.  j a v  a  2 s.c om*/
        for (Teams.Team team : teamsData.teams) {
            MenuItem teamMenuItem = teamsMenu.add(R.id.teams_list_items, Menu.NONE, Menu.NONE, team.teamName);
            if (team.teamName.equals(teamsData.currentTeam.teamName)) {
                teamMenuItem.setChecked(true);
            }
        }
    });
}

From source file:com.android.ted.gank.main.MainActivity.java

private void setupDrawerContent(NavigationView navigationView) {
    navigationView.getMenu().findItem(R.id.nav_home).setChecked(true);
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override//  w  w w  .j a  v a 2 s  . c o  m
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            menuItem.setChecked(true);
            mDrawerLayout.closeDrawers();
            disposeMenuAction(menuItem);
            return true;
        }
    });
}

From source file:com.jefftharris.passwdsafe.sync.SyncLogsFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.fragment_sync_logs, menu);
    super.onCreateOptionsMenu(menu, inflater);

    MenuItem item = menu.findItem(R.id.menu_show_all);
    item.setChecked(itsIsShowAll);
}

From source file:com.grandilo.stanthony.MainActivity.java

private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override//ww w  .  j a  v  a2 s . c o m
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            menuItem.setChecked(true);
            mDrawerLayout.closeDrawers();
            switch (menuItem.getItemId()) {
            case android.R.id.home:
                mDrawerLayout.openDrawer(GravityCompat.START);
                return true;
            case R.id.nav_reminder:
                // A date-time specified in milliseconds since the epoch.
                long startMillis = 0;
                Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
                builder.appendPath("time");
                ContentUris.appendId(builder, startMillis);
                Intent intent = new Intent(Intent.ACTION_VIEW).setData(builder.build());
                startActivity(intent);
                return true;
            case R.id.nav_feedback:
                startActivity(new Intent(MainActivity.this, FeedBack.class));
                return true;
            case R.id.nav_about:
                startActivity(new Intent(MainActivity.this, About.class));
                return true;

            }

            return true;
        }
    });
}