导航抽屉,并与Android的活动 [英] Navigation Drawer and with Activity in Android
问题描述
我想出来的导航抽屉(滑轨菜单)中的http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/
I am trying out the navigation drawer (slide menu) given in http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/
通过以上链接的差异和我是不是调用片段,我试图调用活动。当应用程序打开,我无法看到导航抽屉菜单我只能看到与HOME活动的操作栏打开。
The difference with above link and mine is that instead of calling fragments I am trying to call the activity. When the app opens I am not able to see the Navigation drawer menu I can see only the action bar with HOME activity opened.
下面是我改变了code:(?是不是需要有一个片段或我可以使用活动我的抽屉式导航第一屏)
Here is the code that I changed: (Is it necessary to have a fragment or can I use activity for my first screen in Navigation Drawer?)
mTitle = mDrawerTitle = getTitle();
navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
navMenuIcons = getResources().obtainTypedArray(R.array.nav_drawer_icons);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
navDrawerItems = new ArrayList<NavDrawerItem>();
navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(1, -1)));
navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(2, -1),true, "200"));
navMenuIcons.recycle();
mDrawerList.setOnItemClickListener(new SlideMenuClickListener());
adapter = new NavDrawerListAdapter(getApplicationContext(), navDrawerItems);
mDrawerList.setAdapter(adapter);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.drawer,
R.string.drawer_open,
R.string.drawer_close
)
{
public void onDrawerClosed(View view)
{
getActionBar().setTitle(mTitle);
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView)
{
getActionBar().setTitle(mDrawerTitle);
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null)
{
displayView(0);
}
}
private class SlideMenuClickListener implements
ListView.OnItemClickListener
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
displayView(position);
}
}
private void displayView(int position)
{
switch (position)
{
case 0:
//fragment = new HomeFragment();
Intent intent = new Intent(this, Home.class);
startActivity(intent);
return;
case 1:
//fragment = new FindPeopleFragment();
Intent intent1 = new Intent(this, Profile.class);
startActivity(intent1);
break;
case 2:
//fragment = new PhotosFragment();
Intent intent2 = new Intent(this, Details.class);
startActivity(intent2);
break;
default:
break;
}
mDrawerList.setItemChecked(position, true);
mDrawerList.setSelection(position);
setTitle(navMenuTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
}
我要如何解决这个问题,以显示导航抽屉在我家的活动?
How do I fix this to show Navigation drawer on my Home Activity?
更新:
我甚至尝试在这个环节给出以下选项:
I even tried the following option given in this link:
<一个href="http://stackoverflow.com/questions/24456940/how-can-i-call-one-of-my-activity-using-navigation-drawer?rq=1">How我可以叫我的活动之一采用抽屉式导航?,但我仍然没有得到导航滑动菜单。
How can I call one of my activity using navigation drawer ? but I am still not getting the navigation slide menu.
推荐答案
可以这样做... 导航抽屉是从活动的布局,你不能显示在另一个活动的一个活动,你需要使用一个片段为这个!
You can't do that... Navigation drawer is a layout from an activity and you cant show an activity inside another activity, you need to use a fragments for this!
这是活动是一个屏幕,则不能显示在另一个屏幕的屏幕,而是一个片段可以是一个画面的组成部分,并且可以膨胀的片段的活性的一个容器内,然后显示给用户。
An activity is a screen, you cant show a screen inside another screen, but a fragment may be a component of a screen, and you can inflate a fragment inside a container of an activity and then show to the user.
如果你wan't做到这一点,你可以创建一个抽象的活动和继承,但你不会有一个片段AA活动,您将有每一个多种活动与自己的抽屉式导航。
if you wan't do this, you can create a abstract activity and inherit, but you will not have a a activity in a fragment, you will have a multiple activities with each one with your own navigation drawer.
这篇关于导航抽屉,并与Android的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!