android.support.v4.widget.DrawerLayout.setDrawerListener()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(155)

本文整理了Java中android.support.v4.widget.DrawerLayout.setDrawerListener()方法的一些代码示例,展示了DrawerLayout.setDrawerListener()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DrawerLayout.setDrawerListener()方法的具体详情如下:
包路径:android.support.v4.widget.DrawerLayout
类名称:DrawerLayout
方法名:setDrawerListener

DrawerLayout.setDrawerListener介绍

[英]Set a listener to be notified of drawer events.
[中]将侦听器设置为收到抽屉事件的通知。

代码示例

代码示例来源:origin: bingoogolapple/BGARefreshLayout-Android

private void setUpNavDrawer() {
  mDrawerToggle = new ActionBarDrawerToggle(this,
      mDrawerLayout,
      mToolbar,
      R.string.app_name,
      R.string.app_name);
  mDrawerLayout.setDrawerListener(mDrawerToggle);
  mDrawerToggle.syncState();
}

代码示例来源:origin: wangdan/AisenWeiBo

private void setupDrawer(Bundle savedInstanceState) {
  drawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
      getToolbar(), R.string.draw_open, R.string.draw_close) {
    public void onDrawerClosed(View view) {
      super.onDrawerClosed(view);
    }
    public void onDrawerOpened(View drawerView) {
      super.onDrawerOpened(drawerView);
    }
  };
  mDrawerLayout.setDrawerListener(drawerToggle);
}

代码示例来源:origin: stackoverflow.com

public class MainActivity extends Activity {
final String[] data ={"one","two","three"};

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

   ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data);

   final DrawerLayout drawer = (DrawerLayout)findViewById(R.id.drawer_layout);
   final ListView navList = (ListView) findViewById(R.id.drawer);
   navList.setAdapter(adapter);
   navList.setOnItemClickListener(new OnItemClickListener(){
       @Override
       public void onItemClick(AdapterView<?> parent, View view, final int pos,long id){
           drawer.setDrawerListener( new DrawerLayout.SimpleDrawerListener(){
               @Override
               public void onDrawerClosed(View drawerView){
                   super.onDrawerClosed(drawerView);

               }
           });
           drawer.closeDrawer(navList);
       }
   });
  }
}

代码示例来源:origin: stackoverflow.com

mDrawerLayout.setDrawerListener(mDrawerToggle);

代码示例来源:origin: robolectric/robolectric

@Implementation
protected void setDrawerListener(DrawerLayout.DrawerListener drawerListener) {
 this.drawerListener = drawerListener;
 directlyOn(realDrawerLayout, DrawerLayout.class).setDrawerListener(drawerListener);
}

代码示例来源:origin: stackoverflow.com

mDrawerLayout.setDrawerListener(mDrawerToggle);

代码示例来源:origin: florent37/MaterialViewPager

@Override
protected void onStart() {
  super.onStart();
  mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  mDrawerToggle = new ActionBarDrawerToggle(this, mDrawer, 0, 0);
  mDrawer.setDrawerListener(mDrawerToggle);
  final ActionBar actionBar = getSupportActionBar();
  if (actionBar != null) {
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setDisplayUseLogoEnabled(false);
    actionBar.setHomeButtonEnabled(true);
  }
}

代码示例来源:origin: EverythingMe/overscroll-decor

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_overscroll_demo);
  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  toolbar.setTitle(R.string.recycler_view_demo_title);
  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 = (NavigationView) findViewById(R.id.drawer_nav);
  navigationView.setNavigationItemSelectedListener(this);
  if (savedInstanceState == null) {
    getFragmentManager().beginTransaction()
        .add(R.id.fragment_placeholder, new RecyclerViewDemoFragment())
        .commit();
  }
}

代码示例来源:origin: iammert/MaterialIntroView

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);
  if (savedInstanceState == null)
    getSupportFragmentManager()
        .beginTransaction()
        .add(R.id.container, new MainFragment())
        .commit();
  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);
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 if (getFragmentManager().findFragmentById(R.id.content) == null) {
  showLorem();
 }
 ListView drawer=(ListView)findViewById(R.id.drawer);
 drawer.setAdapter(new ArrayAdapter<String>(
                       this,
                       R.layout.drawer_row,
                       getResources().getStringArray(R.array.drawer_rows)));
 drawer.setOnItemClickListener(this);
 drawerLayout=(DrawerLayout)findViewById(R.id.drawer_layout);
 toggle=
   new ActionBarDrawerToggle(this, drawerLayout,
                R.drawable.ic_drawer,
                R.string.drawer_open,
                R.string.drawer_close);
 drawerLayout.setDrawerListener(toggle);
 getActionBar().setDisplayHomeAsUpEnabled(true);
 getActionBar().setHomeButtonEnabled(true);
}

代码示例来源:origin: iammert/MaterialIntroView

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_toolbar);
  final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);
  //User toolbar to access the views
  ImageView ivSearch = (ImageView) toolbar.findViewById(R.id.ivToolbarSearch);
  mIvShare = (ImageView) toolbar.findViewById(R.id.ivToolbarShare);
  mIvAbout = (ImageView) toolbar.findViewById(R.id.ivToolbarAbout);
  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);
  //show the intro view
  showIntro(ivSearch, MENU_SEARCH_ID_TAG, getString(R.string.guide_setup_profile), FocusGravity.CENTER);
}

代码示例来源:origin: stackoverflow.com

mDrawerLayout.setDrawerListener(mDrawerToggle);

代码示例来源:origin: rey5137/material

mDrawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {

代码示例来源:origin: joyoyao/superCleanMaster

mDrawerLayout.setDrawerListener(mDrawerToggle);
mDrawerToggle.syncState();

代码示例来源:origin: pockethub/PocketHub

drawerLayout.setDrawerListener(actionBarDrawerToggle);

代码示例来源:origin: commonsguy/cw-omnibus

@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 drawer=(ListView)findViewById(R.id.drawer);
 drawer.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
 String[] rows=getResources().getStringArray(R.array.drawer_rows);
 drawer.setAdapter(new ArrayAdapter<String>(this,
                       R.layout.drawer_row,
                       rows));
 drawer.setOnItemClickListener(this);
 drawerLayout=(DrawerLayout)findViewById(R.id.drawer_layout);
 toggle=
   new ActionBarDrawerToggle(this, drawerLayout,
                R.drawable.ic_drawer,
                R.string.drawer_open,
                R.string.drawer_close);
 drawerLayout.setDrawerListener(toggle);
 getActionBar().setDisplayHomeAsUpEnabled(true);
 getActionBar().setHomeButtonEnabled(true);
 getFragmentManager().addOnBackStackChangedListener(this);
 if (getFragmentManager().findFragmentById(R.id.content) == null) {
  showLorem();
 }
}

代码示例来源:origin: stackoverflow.com

mDrawerLayout.setDrawerListener(mDrawerToggle); // Set the drawer toggle as the DrawerListener

代码示例来源:origin: JZ-Darkal/AndroidHttpCapture

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

代码示例来源:origin: robolectric/robolectric

@Test
public void canGetAndSetDrawerListener() throws Exception {
 DrawerLayout drawerLayout = new DrawerLayout(Robolectric.buildActivity(Activity.class).create().get());
 DrawerLayout.DrawerListener mockDrawerListener = mock(DrawerLayout.DrawerListener.class);
 drawerLayout.setDrawerListener(mockDrawerListener);
 assertThat(shadowOf(drawerLayout).getDrawerListener()).isSameAs(mockDrawerListener);
}

代码示例来源:origin: liuling07/SimpleNews

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  mToolbar = (Toolbar) findViewById(R.id.toolbar);
  setSupportActionBar(mToolbar);
  mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
  mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open,
      R.string.drawer_close);
  mDrawerToggle.syncState();
  mDrawerLayout.setDrawerListener(mDrawerToggle);
  mNavigationView = (NavigationView) findViewById(R.id.navigation_view);
  setupDrawerContent(mNavigationView);
  mMainPresenter = new MainPresenterImpl(this);
  switch2News();
}

相关文章