所以我有一个处理我的碎片的导航抽屉。在那些片段中,我想实现选项卡式导航。我已经搜索了高低,以确定这是否可行。但我找不到它是不是。从查看事物我不认为它是标签片段实现需要FragmentActivity,我的导航抽屉不能使用FragmentActivitys。
NavDrawers可以扩展扩展Fragment但不扩展FragmentActivity的类,这就是为什么我认为这是无法实现的。 Android开发者文档(http://developer.android.com/training/implementing-navigation/lateral.html)上的滑动视图就是为什么我不相信我能做到这一点。除非有不同的方式来实现抽屉,而不是我正在做的事情。
但我也知道Gmail实现了类似的功能。他们有一个NavDrawer实现,具有选项卡式导航功能 - 您可以在电子邮件之间滑动。这给了我一些希望......
任何方向都会很棒。
这是我的navdrawer实现,最重要的是我没有使用v4.support库,我使用的是最近的库:
package us.theotts.apps.italiangrammar;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.support.v4.widget.DrawerLayout;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
import us.theotts.apps.italiangrammar.NavDrawer.NavDrawerItem;
import us.theotts.apps.italiangrammar.NavDrawer.NavDrawerListAdapter;
/**
* http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/
* http://blog.kitesapp.co/moments-of-delight-navigation-drawer-depth/
* git test
*/
public class Home extends Activity {
//implements NavigationDrawerFragment.NavigationDrawerCallbacks {
/**
* Fragment managing the behaviors, interactions and presentation of the navigation drawer.
*/
//private NavigationDrawerFragment mNavigationDrawerFragment;
/**
* Used to store the last screen title. For use in {@link #restoreActionBar()}.
*/
private CharSequence mTitle;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
private String TAG = "Home";
private ArrayList<NavDrawerItem> mNavDrawerItems = new ArrayList<NavDrawerItem>();
private NavDrawerListAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
this.mTitle = "Italian Grammar";
// Initialize our drawer
this.mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
this.mDrawerList = (ListView) findViewById(R.id.left_drawer);
// Set the adapter for our drawer
this.mDrawerList.setAdapter(
new ArrayAdapter<String>(
this,
R.layout.redundant_text_view,
getResources().getStringArray(R.array.drawer_titles)
)
);
// Set the click listener
this.mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
for(String s : getResources().getStringArray(R.array.drawer_titles)) {
this.mNavDrawerItems.add(new NavDrawerItem(s));
}
// setting the nav drawer list adapter
this.mAdapter = new NavDrawerListAdapter(getApplicationContext(),
this.mNavDrawerItems);
mDrawerList.setAdapter(this.mAdapter);
this.mDrawerToggle = new ActionBarDrawerToggle(
this,
this.mDrawerLayout,
R.drawable.ic_drawer,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close
) {
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
}
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mTitle);
}
};
this.mDrawerLayout.setDrawerListener(this.mDrawerToggle);
// enabling action bar app icon and behaving it as toggle button
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
}
public void onSectionAttached(int number) {
mTitle = getResources().getStringArray(R.array.drawer_titles)[number-1];
}
public void restoreActionBar() {
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(mTitle);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
if (this.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);
}
}
@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);
}
private class DrawerItemClickListener implements ListView.OnItemClickListener {
public void onItemClick(AdapterView parent, View view, int position, long id) {
selectItem(position);
}
}
private void selectItem(int position) {
// Highlight the selected item, change the title and close the drawer
this.mDrawerList.setItemChecked(position, true);
//setTitle(getResources().getStringArray(R.array.drawer_titles)[position]);
setTitle(getResources().getString(R.string.app_name));
getFragmentManager().beginTransaction()
.replace(R.id.content_frame, Fragment.instantiate(
this, getResources().getStringArray(R.array.drawer_classes)[position]))
.addToBackStack(null).commit();
this.mDrawerLayout.closeDrawer(this.mDrawerList);
}
public void setTitle(CharSequence title) {
this.mTitle = title;
getActionBar().setTitle(title);
}
@Override
public void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
this.mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggls
mDrawerToggle.onConfigurationChanged(newConfig);
}