本文整理汇总了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();
}
示例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);
}
示例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 );
}
示例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);
}
}
示例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);
}
示例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();
}
示例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的时候会重新检查
}
示例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();
}
示例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());
}
}
示例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);
}
示例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);
}
示例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));
}
示例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;
}
});
}
示例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");
// }
// });
}
示例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);
}