当前位置: 首页>>代码示例>>Java>>正文


Java NavigationView.getMenu方法代码示例

本文整理汇总了Java中android.support.design.widget.NavigationView.getMenu方法的典型用法代码示例。如果您正苦于以下问题:Java NavigationView.getMenu方法的具体用法?Java NavigationView.getMenu怎么用?Java NavigationView.getMenu使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.design.widget.NavigationView的用法示例。


在下文中一共展示了NavigationView.getMenu方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onPrepareOptionsMenu

import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    Menu nv = navigationView.getMenu();
    MenuItem mloginstatus = nv.findItem(R.id.nav_loginstatus);
    SharedPreferences sharedPref = getSharedPreferences("sharedPref", Context.MODE_PRIVATE);
    loggedIn = sharedPref.getBoolean("isLoggedIn", false);
    mServer = sharedPref.getString("server", null);

    if (loggedIn) {
        mloginstatus.setTitle(R.string.nav_logout);
        Log.i(TAG, "User is logged in!");
    } else {
        mloginstatus.setTitle(R.string.nav_login);
        Log.i(TAG, "User is not logged in!");
    }
    if (mServer != null) {
        setVersion(mServer);
    } else {
        setVersion("http://hampager.de:8080");
        //if mServer == null
        // setVersion("http://dapnet.db0sda.ampr.org:8080")
    }

    return true;
}
 
开发者ID:DecentralizedAmateurPagingNetwork,项目名称:DAPNETApp,代码行数:27,代码来源:MainActivity.java

示例2: updateDrawerUserInformation

import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
/**
 * Update user information in drawer
 */
private void updateDrawerUserInformation() {
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_drawer);
    Menu menu = navigationView.getMenu();
    MenuItem userName = menu.findItem(R.id.nav_user_name);
    userName.setTitle(SharedPrefClass.getFirstName(this) + " " + SharedPrefClass.getLastName(this));
    MenuItem userEmail = menu.findItem(R.id.nav_user_email);
    userEmail.setTitle(SharedPrefClass.getEmail(this));
    MenuItem userPoints = menu.findItem(R.id.nav_user_points);
    userPoints.setTitle(Integer.toString(SharedPrefClass.getPoints(this)) + " points");
}
 
开发者ID:carlosfaria94,项目名称:UbiBike-client,代码行数:14,代码来源:Station.java

示例3: onCreateOptionsMenu

import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (sequenceIds == null) {
        getMenuInflater().inflate(R.menu.main, menu);
        if (BuildConfig.FLAVOR == "free") {
            NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
            Menu menuNavigationView = navigationView.getMenu();
            menuNavigationView.findItem(R.id.menu_item_user_groups).setVisible(false);
        }
        return true;
    }
    return false;
}
 
开发者ID:white-collar,项目名称:mobile-grammar,代码行数:14,代码来源:AllArticlesListViewActivity.java

示例4: getCheckedItem

import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
private int getCheckedItem(NavigationView navigationView) {
    Menu menu = navigationView.getMenu();
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        if (item.isChecked()) {
            return i;
        }
    }

    return -1;
}
 
开发者ID:anonymous-ME,项目名称:Automata,代码行数:12,代码来源:Main.java

示例5: onCreate

import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.setContentView(R.layout.activity_base_drawer);

    appController = (AppController) this.getApplicationContext();

    mFrameLayout = (FrameLayout) findViewById(R.id.content_frame);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

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

    mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    mNavigationView.setNavigationItemSelectedListener(this);
    menu = mNavigationView.getMenu();
    rebuildMenu();
    loadTravelerId();
}
 
开发者ID:trvlrch,项目名称:trvlr-android,代码行数:29,代码来源:BaseDrawerActivity.java

示例6: onCreate

import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    // 设置Toolbar
    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.addDrawerListener(toggle);
    toggle.syncState();

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

    // 新建Activity时模拟点击首页
    MenuItem item = navigationView.getMenu().getItem(0);
    if (item != null && lastFgTag == null) {
        onNavigationItemSelected(item);
    }

    // 获取侧滑导航栏项目
    retrieveDrawerMenu();
}
 
开发者ID:dianlujitao,项目名称:BigNews,代码行数:30,代码来源:MainActivity.java

示例7: visibleBtn

import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
private void visibleBtn(boolean darkTheme){
    NavigationView navigationView = findViewById(R.id.nav_view);
    Menu menu = navigationView.getMenu();
    MenuItem darkBtn = menu.findItem(R.id.toggle_theme);
    MenuItem lightBtn = menu.findItem(R.id.light_theme);

    if (darkTheme){
        darkBtn.setVisible(false);
        lightBtn.setVisible(true);
    }
    else {
        darkBtn.setVisible(true);
        lightBtn.setVisible(false);
    }
}
 
开发者ID:jboss-outreach,项目名称:lead-management-android,代码行数:16,代码来源:MainActivity.java

示例8: onCreate

import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    setupToolbar(R.id.toolbar, "COOK IT", R.color.colorPink, R.color.colorWhiteTrans, R.drawable.ic_burger);

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

    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);

    Menu m = navigationView.getMenu();
    for (int i=0;i<m.size();i++) {
        MenuItem mi = m.getItem(i);
        SubMenu subMenu = mi.getSubMenu();
        if (subMenu!=null && subMenu.size() >0 ) {
            for (int j=0; j <subMenu.size();j++) {
                MenuItem subMenuItem = subMenu.getItem(j);
                applyFontToMenuItem(subMenuItem);
            }
        }
        applyFontToMenuItem(mi);
    }

    View header = navigationView.getHeaderView(0);
    ImageView imageView = (ImageView) header.findViewById(R.id.imageView);
    Glide.with(this)
            .load(Uri.parse("https://s3.amazonaws.com/uifaces/faces/twitter/jsa/128.jpg"))
            .transform(new CircleGlide(this))
            .into(imageView);
}
 
开发者ID:ahmadnurhidayat,项目名称:Cook-It-Android-XML-Template,代码行数:42,代码来源:Main.java

示例9: onCreate

import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_home);

    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    if (savedInstanceState != null) {
        selectedPosition = savedInstanceState.getInt(SELECTED_POSITION);
        exampleId = savedInstanceState.getString(EXAMPLE_ID);
    }

    progress = new ProgressDialog(this, R.style.SciChart_ExportProgressDialogStyle);
    progress.setTitle("");
    progress.setMessage("Loading data...");
    progress.setIndeterminate(true);
    progress.setCancelable(false);
    progress.setCanceledOnTouchOutside(false);
    progress.show();

    toolbar = (Toolbar) findViewById(R.id.appToolbar);
    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) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    navMenu = navigationView.getMenu();
    catTitle = (TextView) findViewById(R.id.category_title);
    catIcon = (ImageView) findViewById(R.id.category_icon);

    initLayout(savedInstanceState);

    Thread.setDefaultUncaughtExceptionHandler(this);
}
 
开发者ID:ABTSoftware,项目名称:SciChart.Android.Examples,代码行数:43,代码来源:HomeActivity.java

示例10: onCreate

import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
@Override protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main2);
  StatusBarCompat.compat(this, 0x20000000);

  toolbar = (Toolbar) findViewById(R.id.toolbar);
  toolbar.setBackgroundColor(0x0f00ff);
  setSupportActionBar(toolbar);

  drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  ActionBarDrawerToggle toggle =
      new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open,
          R.string.navigation_drawer_close) {
        @Override public void onDrawerOpened(View drawerView) {
          super.onDrawerOpened(drawerView);
          System.out.println("drawer open");
          showFragment = false;
          getUserEvent();
        }
      };
  drawer.setDrawerListener(toggle);
  toggle.syncState();

  navigationView = (NavigationView) findViewById(R.id.nav_view);
  menu = navigationView.getMenu();
  //menu.findItem(R.id.nav_release).setVisible(false);
  menu.findItem(R.id.nav_change).setVisible(false);
  navigationView.setNavigationItemSelectedListener(this);

  headerView = navigationView.getHeaderView(0);
  if (headerView != null) {
    headerView.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        if (ApiHelper.getInstance().loginStatus()) {
          Bundle bundle = new Bundle();
          bundle.putString(UserInfoFragment.User_Name,
              ApiHelper.getInstance().getEmail() + "@" + getString(R.string.title_email_suffix));
          bundle.putString("title", getString(R.string.toolbar_user_info));
          ActivityUtils.startFragment(HomeActivity.this, LConsts.FragmentType.UserInfo, bundle);
        }
      }
    });
    tvCompany = (TextView) headerView.findViewById(R.id.tvCompany);
    tvEmail = (TextView) headerView.findViewById(R.id.tvEmail);
    ivHeader = (ImageView) headerView.findViewById(R.id.imageView);
    tvEmail.setText(ApiHelper.getInstance().getEmail());
  }

  //navigationView.setLis

  supportFragmentManager = getSupportFragmentManager();
  showFragment = true;
  getUserEvent();

  initRxBus();
}
 
开发者ID:Lingzh0ng,项目名称:ITSM,代码行数:57,代码来源:HomeActivity.java

示例11: setupDrawerLayout

import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
/**
 * Initialize the drawer and apply a custom color for every item.
 */
private void setupDrawerLayout() {
    drawerLayout = findViewById(R.id.drawer_layout);
    NavigationView navigationView = findViewById(R.id.navigation_view);
    navigationView.setItemIconTintList(null);
    navigationView.setNavigationItemSelectedListener(this);
    View header = navigationView.getHeaderView(0);
    header.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, LoginActivity.class));
            drawerLayout.closeDrawers();
        }
    });

    final Toolbar toolbar = findViewById(R.id.toolbar);
    ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(
            this,  drawerLayout, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close
    );
    drawerLayout.addDrawerListener(actionBarDrawerToggle);
    actionBarDrawerToggle.syncState();

    Drawable icon;
    if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
        icon = getDrawable(R.drawable.circle);
    } else {
        icon = getResources().getDrawable(R.drawable.circle);
    }
    Menu menu = navigationView.getMenu();
    if (getIntent().getExtras() == null) {
        menu.getItem(1).setChecked(true);
    } else {
        int index = getIntent().getExtras().getInt(Constants.EXTRA_INDEX_CATEGORY, 1);
        menu.getItem(index).setChecked(true);
    }
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        int colorId = colorCats.get(item.getItemId());
        if (colorId > 0 && icon != null) {
            // Item must be "cloned" in order to apply a new color, otherwise we're just updating the same object reference
            Drawable.ConstantState constantState = icon.getConstantState();
            if (constantState != null) {
                Drawable clone = constantState.newDrawable();
                int color = ContextCompat.getColor(getBaseContext(), colorId);
                if (colorId == R.color.cat_color_news && ThemeUtils.isDarkTheme(getBaseContext())) {
                    color = ContextCompat.getColor(getBaseContext(), R.color.cat_color_news_dark);
                }
                clone.setColorFilter(color, PorterDuff.Mode.SRC);
                item.setIcon(clone);
            }
        }
    }
}
 
开发者ID:MBach,项目名称:LeMondeRssReader,代码行数:57,代码来源:MainActivity.java

示例12: onCreate

import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation);

    // START Google sign in API client
    // configure sign-in to request user info
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .requestIdToken(Constants.SERVER_CLIENT_ID)
            .requestServerAuthCode(Constants.SERVER_CLIENT_ID)
            .build();

    // build client with access to Google Sign-In API and the options specified by gso
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();
    // END Google sign in API client

    // START prepare main layout
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    mProgressBar = findViewById(R.id.progressBar);

    mSwipeRefreshLayout = findViewById(R.id.swipe_container);
    mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.colorAccent));
    mSwipeRefreshLayout.setRefreshing(true);
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            updateAndDisplayRegisteredKeys();
        }
    });

    mRecyclerView = findViewById(R.id.list);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mAdapter = new SecurityTokenAdapter(new ArrayList<Map<String, String>>(),
            R.layout.row_token, U2FDemoActivity.this);
    // END prepare main layout

    // START prepare drawer layout
    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.setDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    navigationView.setItemIconTintList(null);
    View header = navigationView.getHeaderView(0);
    mUserEmailTextView = header.findViewById(R.id.userEmail);
    mDisplayNameTextView = header.findViewById(R.id.displayName);
    Menu menu = navigationView.getMenu();
    mU2fOperationMenuItem = menu.findItem(R.id.nav_u2fOperations);
    mSignInMenuItem = menu.findItem(R.id.nav_signin);
    mSignOutMenuItem = menu.findItem(R.id.nav_signout);
    mSignInButton = findViewById(R.id.sign_in_button);
    mSignInButton.setSize(SignInButton.SIZE_WIDE);
    mSignInButton.setScopes(gso.getScopeArray());
    mSignInButton.setOnClickListener(this);
    // END prepare drawer layout

    // request SignIn or load registered tokens
    updateUI();
}
 
开发者ID:googlesamples,项目名称:android-fido,代码行数:71,代码来源:U2FDemoActivity.java


注:本文中的android.support.design.widget.NavigationView.getMenu方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。