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


Java NavigationView.setNavigationItemSelectedListener方法代码示例

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


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

示例1: 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) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    consola = (TextView) findViewById(R.id.log);
    log = "";
    ok = false;

    et1 = (EditText)findViewById(R.id.threshold);
    et2 = (EditText)findViewById(R.id.window_len);
    et3 = (EditText)findViewById(R.id.maxts);
    et4 = (EditText)findViewById(R.id.readyforescast);

    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);
}
 
开发者ID:borjalor,项目名称:DroidSentinel,代码行数:26,代码来源:MainActivity.java

示例2: onCreate

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

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_usuarios);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.usuarios_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.usuarios_nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    navigationView.setCheckedItem(R.id.nav_usuarios);
}
 
开发者ID:EdwardAlexis,项目名称:Sistema-de-Comercializacion-Negocios-Jhordan,代码行数:20,代码来源:Usuarios.java

示例3: onCreate

import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notepad1);
        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) {
                Save("Note1.txt");
            }
        });
*/
        EditText1 = (EditText) findViewById(R.id.EditText1);
        EditText1.setText(Open("Note1.txt"));
        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);
    }
 
开发者ID:ayushghd,项目名称:iSPY,代码行数:26,代码来源:Notepad1.java

示例4: 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) 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 navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}
 
开发者ID:Keniobyte,项目名称:ActiveAlert,代码行数:26,代码来源:MainActivity.java

示例5: initNavDrawer

import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
/**
 * Initialize NavDrawer
 */
private void initNavDrawer() {
    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.addDrawerListener(toggle);
    toggle.syncState();

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

    accountID = (TextView) navigationHeader.findViewById(R.id.nav_drawer_account_id);
    username = (TextView) navigationHeader.findViewById(R.id.nav_drawer_username);
    navHeader = (LinearLayout) navigationHeader.findViewById(R.id.nav_drawer);
}
 
开发者ID:d0pam1n,项目名称:DoorPhone,代码行数:22,代码来源:BaseActivity.java

示例6: setupDrawerContent

import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(
        new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(MenuItem menuItem) {
                menuItem.setChecked(true);
                mDrawerLayout.closeDrawers();
                return true;
            }
        }
    );
}
 
开发者ID:stefanonicolai,项目名称:AstronomyTourPadova,代码行数:13,代码来源:ReceiverActivity.java

示例7: initViews

import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
public void initViews() {
    drawerLayout = (DrawerLayout) activity.findViewById(R.id.drawer_layout);
    navigationView = (NavigationView) activity.findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    homeBackgroundController.initViews(navigationView);
    drawerLayout.addDrawerListener(drawerListener);
    updateSwitchMenuIconAndText();
}
 
开发者ID:DuanJiaNing,项目名称:Musicoco,代码行数:9,代码来源:LeftNavigationController.java

示例8: onCreate

import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_homepage);
    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 navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);


}
 
开发者ID:addy-org,项目名称:Addy-Android,代码行数:28,代码来源:Homepage.java

示例9: onCreate

import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    Timber.d("on create %s", MainActivity.this);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

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

    transactionHelper = new FragmentTransactionHelper(getSupportFragmentManager(), R.id.fragment_container);
    transactionHelper.setCurrentItem(R.id.nav_today);

    workflow = new Workflow(this);
    workflow.start();
    RxPermissions permissions = new RxPermissions(this);
    permissions.request(Manifest.permission.READ_SMS)
            .subscribe(new Consumer<Boolean>() {
                @Override
                public void accept(Boolean aBoolean) throws Exception {
                    if (aBoolean) {
                        workflow.scan();
                    }
                }
            });
    permissions.request(Manifest.permission.CALL_PHONE);

    handleIntent(getIntent());
}
 
开发者ID:jonashao,项目名称:Samantha,代码行数:38,代码来源:MainActivity.java

示例10: onCreate

import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_default);
    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();
        }
    });

    drawer = (AdvanceDrawerLayout) 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);


}
 
开发者ID:shiburagi,项目名称:Drawer-Behavior,代码行数:28,代码来源:DefaultDrawerActivity.java

示例11: prepareDrawer

import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
private void prepareDrawer(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(
            new NavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(MenuItem item) {
                    item.setChecked(true);
                    navigate(item);
                    drawerLayout.closeDrawers();
                    return true;
                }
            }
    );
}
 
开发者ID:kflauri2312lffds,项目名称:Android_watch_magpie,代码行数:14,代码来源:MainActivity.java

示例12: onCreate

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

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("Menu");
    setSupportActionBar(toolbar);

    //init firebase
    database = FirebaseDatabase.getInstance();
    category=database.getReference("Category");


 BottomNavigationView fab = (BottomNavigationView) 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);

    // set Name for user

    View headerView = navigationView.getHeaderView(0);
    txtFullName=(TextView)headerView.findViewById(R.id.txtFullName);
    txtFullName.setText(Common.currentUse.getName());

    //load menu
    recycler_menu =(RecyclerView)findViewById(R.id.recycler_menu);
    recycler_menu.setHasFixedSize(true);
    layoutManager= new LinearLayoutManager(this);
    recycler_menu.setLayoutManager(layoutManager);

    loadMenu();

}
 
开发者ID:8155220,项目名称:eatit,代码行数:49,代码来源:Home.java

示例13: onCreate

import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    // init persistence
    BuylistOpenHelper database = new BuylistOpenHelper(this);
    initShoptypeStrings(); // init Strings after Resource Loading

    // init Services
    /// main service on which all other services rely on
    MainService.getInstance();
    try {
        //// set persistence of main service
        MainService.getInstance().setDb(database);
    } catch (Exception e) {
        e.printStackTrace();
    }

    /// init settings service
    SettingsService.getInstance();

    /// init pojo services
    ShopService.getInstance();
    ShoplistService.getInstance();
    ItemService.getInstance();

    /// init feature managment
    FeatureService.getInstance();

    //// init sensors und features
    ShakeSensorFeature ssf = new ShakeSensorFeature(this);
    FeatureService.getInstance().addSensorFeature(ssf);

    // load settings from saved state
    SettingsService.getInstance().initSettingKeys(this);
    SettingsService.getInstance().loadSettings(this);
    // create all settings if not present (after update or first install or so)
    installNonExistentSettings();

    // set content to main engine file
    setContentView(R.layout.activity_main);

    // add this activity to observe the features
    FeatureService.getInstance().addObserver(this);

    // find navigation sidebar (sidemenu that slides open) and assign action handling
    final NavigationView navigationView = (NavigationView) findViewById(R.id.activity_main_navigation);
    navigationView.setNavigationItemSelectedListener(navigationHandler);

    // set action for menu hamburger to open the menu drawer
    findViewById(R.id.activity_main_hamburger).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
            drawer.openDrawer(GravityCompat.START);
        }
    });

    // push opening fragment to queueing list and display it
    if (QueueHolder.contentQueue.isEmpty() || !QueueHolder.contentQueue.peek().getClass().equals(QueueHolder.viewingFragment.getClass()))
        QueueHolder.contentQueue.push(QueueHolder.viewingFragment);
    displayFragment(QueueHolder.viewingFragment);

    // show welcome screen (tooltips) if enabled
    if (SettingsService.getInstance().getSetting(SettingsService.SETTING_SHOW_STARTUP_TOOLTIP_TUTORIAL).equals("true") && !tooltipOpen) {
        new BeginTooltipDialogFragment().show(getFragmentManager(), "tooltips");
        tooltipOpen = true;
    }

    // call super method
    super.onCreate(savedInstanceState);
}
 
开发者ID:marc-urschick,项目名称:a_whattobuy,代码行数:71,代码来源:MainActivity.java

示例14: onCreate

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

    ButterKnife.bind(this);
    setSupportActionBar(toolbar);

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

    resetObdButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getPresenter().resetObd();
        }
    });

    if (getPresenter().getAccountId() == null) {
        getPresenter().initAccount();
    }

    mSettingBtDeviceProgressDialog = new ProgressDialog(this);
    mSettingBtDeviceProgressDialog.setMessage(getString(R.string.setting_bt_device));
    mSettingBtDeviceProgressDialog.setCancelable(false);

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

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        ActivityCompat.requestPermissions(MainActivity.this,
                new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
                        Manifest.permission.READ_LOGS,
                        Manifest.permission.READ_EXTERNAL_STORAGE
                },
                1);
    }

    if (getPresenter().isProducerRunning) {
        setStartProducerButtonEnabled(true);
    }

    if (!getPresenter().isServiceBound()) {
        Intent obdBluetoothServiceIntent = new Intent(this, ObdBluetoothService.class);
        bindService(obdBluetoothServiceIntent, getPresenter().serviceConnection(), BIND_AUTO_CREATE);
    } else {
        changeTextAndHandlerForNavBtConnectionStop();
    }
}
 
开发者ID:kocur,项目名称:Obd2-Tracker,代码行数:52,代码来源:MainActivity.java

示例15: onCreate

import android.support.design.widget.NavigationView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Adding Toolbar to Main screen
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // Setting ViewPager for each Tabs
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    setupViewPager(viewPager);
    // Set Tabs inside Toolbar
    TabLayout tabs = (TabLayout) findViewById(R.id.tabs);
    tabs.setupWithViewPager(viewPager);
    // Create Navigation drawer and inlfate layout
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer);
    // Adding menu icon to Toolbar
    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
        VectorDrawableCompat indicator
                = VectorDrawableCompat.create(getResources(), R.drawable.ic_menu, getTheme());
        indicator.setTint(ResourcesCompat.getColor(getResources(),R.color.white,getTheme()));
        supportActionBar.setHomeAsUpIndicator(indicator);
        supportActionBar.setDisplayHomeAsUpEnabled(true);
    }
    // Set behavior of Navigation drawer
    navigationView.setNavigationItemSelectedListener(
            new NavigationView.OnNavigationItemSelectedListener() {
                // This method will trigger on item Click of navigation menu
                @Override
                public boolean onNavigationItemSelected(MenuItem menuItem) {
                    // Set item in checked state
                    menuItem.setChecked(true);

                    // TODO: handle navigation

                    // Closing drawer on item click
                    mDrawerLayout.closeDrawers();
                    return true;
                }
            });
    // Adding Floating Action Button to bottom right of main view
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Snackbar.make(v, "Hello Snackbar!",
                    Snackbar.LENGTH_LONG).show();
        }
    });
}
 
开发者ID:TORU0239,项目名称:android-design-library-master,代码行数:52,代码来源:MainActivity.java


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