我不知道怎么才能停止滑动菜单。我想删除可以滑动的幻灯片菜单。我试着用代码注释。但我无法停止扮演slidemenu。
下面是我的代码。你能帮助我吗?非常感谢!:)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState != null) {
finish();
return;
}
getActionBar().setDisplayShowHomeEnabled(false);
getActionBar().setDisplayShowTitleEnabled(false);
//getActionBar().hide();
mTitle = mDrawerTitle = getTitle();
// load slide menu items
navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
//
// // nav drawer icons from resources
navMenuIcons = getResources()
.obtainTypedArray(R.array.nav_drawer_icons);
//
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.list_slidermenu);
//navDrawerItems = new ArrayList<NavDrawerItem>();
// adding nav drawer items to array
// Home
// navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
// // Find People
// navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));
// // Photos
// navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));
// // Communities, Will add a counter here
// navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1), true, "22"));
// // Pages
// navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));
// // What's hot, We will add a counter here
// navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1), true, "50+"));
// Recycle the typed array
// navMenuIcons.recycle();
//
// mDrawerList.setOnItemClickListener(new SlideMenuClickListener());
//
// // setting the nav drawer list adapter
// adapter = new NavDrawerListAdapter(getApplicationContext(),
// navDrawerItems);
// mDrawerList.setAdapter(adapter);
// enabling action bar app icon and behaving it as toggle button
//getActionBar().setDisplayHomeAsUpEnabled(true);
//getActionBar().setHomeButtonEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer, //nav menu toggle icon
R.string.app_name, // nav drawer open - description for accessibility
R.string.app_name // nav drawer close - description for accessibility
) {
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
// calling onPrepareOptionsMenu() to show action bar icons
//invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mDrawerTitle);
// calling onPrepareOptionsMenu() to hide action bar icons
//invalidateOptionsMenu();
}
};
//
//
// if (savedInstanceState == null) {
// // on first time display view for first nav item
// displayView(0);
// }
// Set up the action bar.
//final ActionBar actionBar = getActionBar();
getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Create the adapter that will return a fragment for each of the three
// primary sections of the app.
mSectionsPagerAdapter = new SectionsPagerAdapter(
getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager.setOffscreenPageLimit(4);
// When swiping between different sections, select the corresponding
// tab. We can also use ActionBar.Tab#select() to do this if we have
// a reference to the Tab.
mViewPager
.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
getActionBar().setSelectedNavigationItem(position);
}
});
// For each of the sections in the app, add a tab to the action bar.
//for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
// Create a tab with text corresponding to the page title defined by
// the adapter. Also specify this Activity object, which implements
// the TabListener interface, as the callback (listener) for when
// this tab is selected.
getActionBar().setStackedBackgroundDrawable(getResources().getDrawable(
R.drawable.background));
getActionBar().addTab(getActionBar().newTab()
//.setText(mSectionsPagerAdapter.getPageTitle(0))
.setTabListener(this)
.setIcon(R.drawable.tmon)
//.setText(mSectionsPagerAdapter.getPageTitle(0))
);
getActionBar().addTab(getActionBar().newTab()
.setIcon(R.drawable.coupang)
//.setText(mSectionsPagerAdapter.getPageTitle(1))
.setTabListener(this));
getActionBar().addTab(getActionBar().newTab()
//.setText(mSectionsPagerAdapter.getPageTitle(2))
.setIcon(R.drawable.wemef)
.setTabListener(this));
getActionBar().addTab(getActionBar().newTab()
.setIcon(R.drawable.oclock)
//.setText(mSectionsPagerAdapter.getPageTitle(3))
.setTabListener(this));
//getActionBar().setIcon(R.drawable.tmon);
//}
getActionBar().addTab(getActionBar().newTab()
.setIcon(R.drawable.search)
//.setText(mSectionsPagerAdapter.getPageTitle(4))
.setTabListener(this));
}
/**
* Slide menu item click listener
* */
// private class SlideMenuClickListener implements
// ListView.OnItemClickListener {
// @Override
// public void onItemClick(AdapterView<?> parent, View view, int position,
// long id) {
// // display view for selected nav drawer item
// displayView(position);
// }
// }
//tab
public void onTabSelected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
// When the given tab is selected, switch to the corresponding page in
// the ViewPager.
mViewPager.setCurrentItem(tab.getPosition());
}
public void onTabUnselected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
}
public void onTabReselected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
}
/**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
Context mContext;
public SectionsPagerAdapter(android.support.v4.app.FragmentManager fm) {
super(fm);
}
@Override
public android.support.v4.app.Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a DummySectionFragment (defined as a static inner class
// below) with the page number as its lone argument.
switch(position) {
case 0:
return new Tab1();
case 1:
return new Tab2();
case 2:
return new Tab3();
case 3:
return new Tab4();
case 4:
return new Tab5();
}
return null;
}
@Override
public int getCount() {
// Show 5 total pages.
return 5;
}
@Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return getString(R.string.title_section1).toUpperCase(l);
case 1:
return getString(R.string.title_section2).toUpperCase(l);
case 2:
return getString(R.string.title_section3).toUpperCase(l);
case 3:
return getString(R.string.title_section4).toUpperCase(l);
case 4:
return getString(R.string.title_section5).toUpperCase(l);
}
return null;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// toggle nav drawer on selecting action bar app icon/title
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle action bar actions click
switch (item.getItemId()) {
case R.id.action_settings:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
/* *
* Called when invalidateOptionsMenu() is triggered
*/
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// if nav drawer is opened, hide the action items
boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
return super.onPrepareOptionsMenu(menu);
}
/**
* Diplaying fragment view for selected nav drawer list item
* */
// private void displayView(int position) {
// // update the main content by replacing fragments
// Fragment fragment = null;
// switch (position) {
// case 0:
// fragment = new HomeFragment();
// break;
// case 1:
// fragment = new FindPeopleFragment();
// break;
// case 2:
// fragment = new PhotosFragment();
// break;
// case 3:
// fragment = new CommunityFragment();
// break;
// case 4:
// fragment = new PagesFragment();
// break;
// case 5:
// fragment = new WhatsHotFragment();
// break;
//
// default:
// break;
// }
//
// if (fragment != null) {
// FragmentManager fragmentManager = getFragmentManager();
// fragmentManager.beginTransaction()
// .replace(R.id.frame_container, fragment).commit();
//
// // update selected item and title, then close the drawer
// mDrawerList.setItemChecked(position, true);
// mDrawerList.setSelection(position);
// setTitle(navMenuTitles[position]);
// mDrawerLayout.closeDrawer(mDrawerList);
// } else {
// // error in creating fragment
// Log.e("MainActivity", "Error in creating fragment");
// }
// }
@Override
public void setTitle(CharSequence title) {
mTitle = title;
getActionBar().setTitle(mTitle);
}
/**
* When using the ActionBarDrawerToggle, you must call it during
* onPostCreate() and onConfigurationChanged()...
*/
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggls
mDrawerToggle.onConfigurationChanged(newConfig);
}
}
我想您想防止滑动手势打开导航抽屉,因为它会干扰选项卡之间的滑动?此问题的解决方案在此处的堆栈溢出中描述:
在onCreate()中使用
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
锁定抽屉布局,使其不会用手势打开。并使用以下工具解锁:
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
(或使用LOCK\u MODE\u LOCKED\u open强制打开)。
目前,我正在尝试插入一个下拉式滑动菜单(不确定它的名称)。其想法是用户触摸箭头或菜单的任何区域,然后向上拖动以打开菜单。但我不知道如何或在哪里可以找到这方面的教程。
我正在我的应用程序中使用带有ActionBarSherlock的滑动菜单。动作条和滑动菜单工作良好,但我希望滑动菜单只滑动内容,而不是动作条像最新版本的youtube应用程序。 这在SlidingMenu中是可能的吗?如果是,请说明如何 提前致谢 下面是我的actionbar和slidingmenu代码
我想在我的应用程序中创建从下到上滚动的滑动菜单。我在活动的底部有一个按钮,当用户点击按钮时,菜单就会显示出来。当用户再次点击按钮时,菜单应该消失。用户还可以上下滑动以显示或消失菜单。 菜单可以像这个应用程序中的任何一个。做 请看下面的截图。你知道怎么做吗?你有什么建议吗?
我试着让滑动抽屉菜单和脸书应用程序中的一样。我在这里提出了很多像这样的问题。找到了很多库,但它们都在不同的库中从左向右或从右向左滑动。我想让它从两侧滑动,通过顶部栏中的两个按钮从左向右和从右向左滑动。有人能帮我吗。 提前感谢。
本文向大家介绍Android利用滑动菜单框架实现滑动菜单效果,包括了Android利用滑动菜单框架实现滑动菜单效果的使用技巧和注意事项,需要的朋友参考一下 之前我向大家介绍了史上最简单的滑动菜单的实现方式,相信大家都还记得。如果忘记了其中的实现原理或者还没看过的朋友,请先去看一遍之前的文章Android仿人人客户端滑动菜单的侧滑特效实现代码,史上最简单的侧滑实现 ,因为我们今天要实现的滑动菜单框架
本文向大家介绍Android滑动优化高仿QQ6.0侧滑菜单(滑动优化),包括了Android滑动优化高仿QQ6.0侧滑菜单(滑动优化)的使用技巧和注意事项,需要的朋友参考一下 推荐阅读:Android使用ViewDragHelper实现仿QQ6.0侧滑界面(一) 但是之前的实现,只是简单的可以显示和隐藏左侧的菜单,但是特别生硬,而且没有任何平滑的趋势,那么今天就来优化一下吧,加上平滑效果,而且可