當前位置: 首頁>>代碼示例>>Java>>正文


Java DrawerLayout.addDrawerListener方法代碼示例

本文整理匯總了Java中android.support.v4.widget.DrawerLayout.addDrawerListener方法的典型用法代碼示例。如果您正苦於以下問題:Java DrawerLayout.addDrawerListener方法的具體用法?Java DrawerLayout.addDrawerListener怎麽用?Java DrawerLayout.addDrawerListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v4.widget.DrawerLayout的用法示例。


在下文中一共展示了DrawerLayout.addDrawerListener方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onCreate

import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

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

    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.setDrawerIndicatorEnabled(true);
    toggle.syncState();
}
 
開發者ID:barnhill,項目名稱:SimpleBible,代碼行數:20,代碼來源:MainActivity.java

示例2: onCreate

import android.support.v4.widget.DrawerLayout; //導入方法依賴的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

示例3: setSideBarDrawer

import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
private void setSideBarDrawer( DrawerLayout mDrawer, NavigationView navView,
                               Toolbar toolbar, DBHelper helper) {
    // enables toggle button on toolbar to open the sidebar
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, mDrawer, toolbar, R.string.navigation_drawer_open,
            R.string.navigation_drawer_close);
    mDrawer.addDrawerListener(toggle);
    toggle.syncState();

    // set up side navigation bar layout
    navView.setNavigationItemSelectedListener(this);

    // Want to display icons in original color scheme
    navView.setItemIconTintList(null);

    // highlight the current location
    navView.setCheckedItem(R.id.nav_matches);

    // sets up TextViews in sidebar to display the user's name and email
    sidebarUserName = (android.widget.TextView) navView.getHeaderView(0)
            .findViewById(R.id.sidebar_username);
    sidebarUserEmail = (android.widget.TextView) navView.getHeaderView(0)
            .findViewById(R.id.sidebar_user_email);
    setSideBarText( sidebarUserName, sidebarUserEmail, helper );
}
 
開發者ID:chrisqz95,項目名稱:couch-potatoes,代碼行數:26,代碼來源:ProfileActivity.java

示例4: onCreate

import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    if(drawerLayout != null){
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawerLayout, toolbar, R.string.nav_opened, R.string.nav_closed);

        drawerLayout.addDrawerListener(toggle);
        if(getSupportActionBar() != null) getSupportActionBar().setHomeButtonEnabled(true);

        toggle.syncState();
    }

    if(navigationView != null){
        navigationView.setNavigationItemSelectedListener(this);
    }
}
 
開發者ID:oragamihawk,項目名稱:OpenOrbitCNCAndroidFrontend,代碼行數:20,代碼來源:BaseNavActivity.java

示例5: onCreate

import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(versionCheck())finish();
//        setContentView(R.layout.activity_md_main);
        setContentView(R.layout.activity_md_main_with_parallax);
        mRootDrawer = (DrawerLayout) findViewById(R.id.root_drawer);
        mCoordinar = (CoordinatorLayout) findViewById(R.id.coordinar);
//        mViewpager = (ViewPager) findViewById(R.id.viewpager);
        //設置數據才能執行下麵的mTabLayout.setupWithViewPager
//        mViewpager.setAdapter(new FragAdapter(getSupportFragmentManager()));
        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        mToolbar.setTitle("MD Demo from H");
        setSupportActionBar(mToolbar);

        mNaviView = (NavigationView) findViewById(R.id.navView);
        NaviItemListener naviItemListener = new NaviItemListener();
        mNaviView.setNavigationItemSelectedListener(naviItemListener);
        mNaviView.getHeaderView(0).setOnClickListener(naviItemListener);
        mFab = (FloatingActionButton) findViewById(R.id.fab);
        mFab.setOnClickListener(this);

        //當沒有使用DrawableLayout的時候可以使用這種方式為按鈕修改圖標
//        final ActionBar ab = getSupportActionBar();
//        ab.setHomeAsUpIndicator(R.drawable.ic_build);
//        ab.setDisplayHomeAsUpEnabled(true);

        mDrawerToggle = new ActionBarDrawerToggle(this, mRootDrawer, mToolbar,
                R.string.toggle_open, R.string.toggle_close);
//        mRootDrawer.setDrawerListener(mDrawerToggle);
        mRootDrawer.addDrawerListener(mDrawerToggle);
        //設置第二個
        mRootDrawer.addDrawerListener(new DrawerLayoutListener());
        //因為被拖出來的drawer遮住了,所以禁用動畫
//        mDrawerToggle.setDrawerSlideAnimationEnabled(false);
        //調用這句才讓圖標顯示出來
        mDrawerToggle.syncState();

        showFragmentByReplace(createFragment(R.id.menu_item_drawer),false);
    }
 
開發者ID:halohoop,項目名稱:AndroidDigIn,代碼行數:41,代碼來源:MDMainActivity.java

示例6: onCreate

import android.support.v4.widget.DrawerLayout; //導入方法依賴的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: initDrawer

import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
/**
     * 初始化抽屜布局
     */
    private void initDrawer() {
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

//        SharedPreferences preferences = getPreferences(MODE_PRIVATE);
        //初始化的時候載入toolBar的顏色
        String tasteChosen = getSharedPreferences("MainActivity", MODE_PRIVATE).getString("tasteChosen", "辣");
        String color = "0";
        if (tasteChosen.equals("辣")) {
            color = "#FF0000";
        } else if (tasteChosen.equals("清淡")) {
            color = "#BFEFFF";
        } else if (tasteChosen.equals("香")) {
            color = "#EEC900";
        } else if (tasteChosen.equals("甜")) {
            color = "#FFAEB9";
        }
        toolbar.setBackgroundColor(Color.parseColor(color));

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

        navigationView.inflateHeaderView(R.layout.main_nav_header_nologin);//預加載一個未登錄的界麵,在onResume的時候會重新檢查
    }
 
開發者ID:GrayXu,項目名稱:HustEating,代碼行數:37,代碼來源:MainActivity.java

示例8: initView

import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
private void initView() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolBar);
    initToolbar(toolbar);
    DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
    /**
     * 菜單控製開關
     */
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, 0, 0);

    mDrawerLayout.addDrawerListener(toggle);
    toggle.syncState();
}
 
開發者ID:weimin96,項目名稱:shareNote,代碼行數:13,代碼來源:MainActivity.java

示例9: onCreate

import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
@SuppressWarnings("ConstantConditions")
@Override
public void onCreate(Bundle state) {
	super.onCreate(state);
	exitIfStartupFailed(getIntent());
	setContentView(R.layout.activity_nav_drawer);

	Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
	drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
	navigation = (NavigationView) findViewById(R.id.navigation);
	GridView transportsView = (GridView) findViewById(R.id.transportsView);

	setSupportActionBar(toolbar);
	getSupportActionBar().setDisplayHomeAsUpEnabled(true);
	getSupportActionBar().setHomeButtonEnabled(true);

	drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,
			R.string.nav_drawer_open_description,
			R.string.nav_drawer_close_description);
	drawerLayout.addDrawerListener(drawerToggle);
	navigation.setNavigationItemSelectedListener(this);

	initializeTransports(getLayoutInflater());
	transportsView.setAdapter(transportsAdapter);

	if (state == null) {
		startFragment(ContactListFragment.newInstance(), R.id.nav_btn_contacts);
	}
	if (getIntent() != null) {
		onNewIntent(getIntent());
	}
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:33,代碼來源:NavDrawerActivity.java

示例10: setUpToolbarWithDrawerLayout

import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
private void setUpToolbarWithDrawerLayout() {
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawerLayout = findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open_drawer, R.string.close_drawer);
    toggle.syncState();
    drawerLayout.addDrawerListener(toggle);
}
 
開發者ID:hyb1996,項目名稱:NodeET,代碼行數:9,代碼來源:MainActivity.java

示例11: onCreate

import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mContext = getApplication().getApplicationContext();

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

    mFragmentContainer = findViewById(R.id.fragment_container);
    mFragmentManager = getSupportFragmentManager();

    if (savedInstanceState != null) {

        Log.d(mActivity, "Restore");
        restore = savedInstanceState.getBoolean("restore");
        mTitleText = savedInstanceState.getString("mTitleText");
        Fragment f = mFragmentManager.findFragmentById(R.id.fragment_container);
        if(f == null) {
            LoadFragment(mTitleText);
        }
    } else {

        restore = false;
        mTitleText = Constants.SCREEN_MAIN;
        LoadFragment(mTitleText);
    }

    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);
}
 
開發者ID:searchy2,項目名稱:AndroidCrossPromotion,代碼行數:38,代碼來源:MainActivity.java

示例12: onCreate

import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    AndroidInjection
            .inject(this);
    super.onCreate(savedInstanceState);
    getWindow().setBackgroundDrawableResource(R.drawable.rounded_back);
    setContentView(R.layout.activity_home);
    rootLayout=findViewById(R.id.home);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    taskList=findViewById(R.id.task_list);
    taskList.setLayoutManager(new LinearLayoutManager(this));

    FloatingActionButton fab =  findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            snackView=view;
            createAddTaskDialog();
        }
    });

    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 = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    taskList.setAdapter(new TaskListAdapter(taskViewModel));
}
 
開發者ID:HassanUsman,項目名稱:Things2Do-Using-MVVM-RxJava-Room,代碼行數:33,代碼來源:Home.java

示例13: onCreate

import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_base);

        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        Toolbar mainToolbar = (Toolbar) findViewById(R.id.main_toolbar);
        setSupportActionBar(mainToolbar);
        mNavigationView = (NavigationView) findViewById(R.id.navigation_view);

//        View logoView = getLayoutInflater().inflate(R.layout.drawer_header, mNavigationView, false);

//        mNavigationView.addHeaderView(logoView);
        mDrawerToggle = new ActionBarDrawerToggle(
                this,
                mDrawerLayout,
                R.string.drawer_open,
                R.string.drawer_close
        );
        mDrawerLayout.addDrawerListener(mDrawerToggle);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);

        mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(MenuItem menuItem) {
                boolean highlight = true;
                switch (menuItem.getItemId()) {
                    case R.id.nav_main:
                        if(!menuItem.isChecked()) {
                            // start activity only if it is not currently checked
                            Intent intentmain = new Intent(BaseActivity.this, MainActivity.class);
                            intentmain.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            startActivity(intentmain);
                        }
                        break;
                    case R.id.nav_add_activity:
                        Intent intentaddact = new Intent(BaseActivity.this, EditActivity.class);
                        startActivity(intentaddact);
                        break;
                    case R.id.nav_activity_manager:
                        Intent intentmanage = new Intent(BaseActivity.this, ManageActivity.class);
                        startActivity(intentmanage);
                        break;
                    case R.id.nav_diary:
                        Intent intentdiary = new Intent(BaseActivity.this, HistoryActivity.class);
                        startActivity(intentdiary);
                        break;
                    case R.id.nav_about:
                        Intent intentabout = new Intent(BaseActivity.this, AboutActivity.class);
                        startActivity(intentabout);
                        break;
                    case R.id.nav_settings:
                        Intent intentsettings = new Intent(BaseActivity.this, SettingsActivity.class);
                        startActivity(intentsettings);
                        break;
                    default:
                        Toast.makeText(BaseActivity.this, menuItem.getTitle() + " is not yet implemented :-(", Toast.LENGTH_LONG).show();
                        break;
                }
                mDrawerLayout.closeDrawers();
                return highlight;
            }
        });
    }
 
開發者ID:ramack,項目名稱:ActivityDiary,代碼行數:68,代碼來源:BaseActivity.java

示例14: onCreate

import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_drawer_layout);

        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        mToolbar.setNavigationIcon(R.drawable.ic_action_back);
        setSupportActionBar(mToolbar);

        mDrawerLayout = (DrawerLayout) findViewById(R.id.DrawerLayout);
        mDrawerToggle = new ActionBarDrawerToggle(
                this,                  /* host Activity */
                mDrawerLayout,         /* DrawerLayout object */
                mToolbar,
                R.string.drawer_open,  /* "open drawer" description for accessibility */
                R.string.drawer_close  /* "close drawer" description for accessibility */
        ) {
            public void onDrawerClosed(View view) {
                getSupportActionBar().setTitle(mTitle);
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }
            public void onDrawerOpened(View drawerView) {
                getSupportActionBar().setTitle(mDrawerTitle);
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }
        };
        mDrawerLayout.addDrawerListener(mDrawerToggle);
//        mDrawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {
//            @Override
//            public void onDrawerSlide(View drawerView, float slideOffset) {
//
//            }
//
//            @Override
//            public void onDrawerOpened(View drawerView) {
//
//            }
//
//            @Override
//            public void onDrawerClosed(View drawerView) {
//
//            }
//
//            @Override
//            public void onDrawerStateChanged(int newState) {
//
//            }
//        });
//        mDrawerLayout.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
//                                        });
//                mDrawerLayout.openDrawer(GravityCompat.START);
//        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//
//                Log.e("Toolbar","setNavigationOnClickListener");
//            }
//        });

    }
 
開發者ID:LinweiJ,項目名稱:MaterialDesignWidget,代碼行數:61,代碼來源:DrawerLayoutActivity.java

示例15: onCreate

import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Save name of activity, in case of calling SettingsActivity
    ActivityUtils.saveStringToPreferences(getApplicationContext(), LAST_ACTIVITY,
            MAIN_ACTIVITY);

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


    SharedPreferences prefs = getSharedPreferences(SHARED_PREF_NAME, 0);
    String page = prefs.getString(ITEM_CATEGORY, MOVIES);

    fragmentLayout = (FrameLayout) findViewById(R.id.fragment_container);
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager(), page);

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);

    // Obtain the FirebaseAnalytics instance.
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

    homeFragment = new HomeFragment();
    favoritesFragment = new FavoritesFragment();
    discoverFragment = new DiscoverFragment();
    discoverResultFragment = new DiscoverResultFragment();
    peopleFragment = new PeopleFragment();
    showPage(page);
    assignCheckedItem(page);
}
 
開發者ID:an-garcia,項目名稱:MovieGuide,代碼行數:43,代碼來源:MainActivity.java


注:本文中的android.support.v4.widget.DrawerLayout.addDrawerListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。