如何使用带有扩展标签活动的子项的滑动菜单,即子项包含标签布局..我知道如何实现滑动菜单但是问题是孩子需要扩展标签的选项卡活动和滑动菜单的基本活动。 / p>
1.BaseActivity for sliding menu:
public class BaseActivity extends Activity {
SharedPreferences pre;
Editor editor;
static int dbcount;
SQLiteDatabase db, db1;
String url;
static TextView tv;
String status, response;
protected FrameLayout frameLayout;
protected ListView mDrawerList;
protected String[] listArray = { "Veg Starters","Veg Burgers",
"Non-Veg Starters","Non-Veg Burgers","Veg Wraps","Non-Veg Wraps" };
protected static int position;
private DrawerLayout mDrawerLayout;
@SuppressWarnings("deprecation")
private ActionBarDrawerToggle actionBarDrawerToggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.navigation_drawer);
// Shared pref
pre = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
// create database if not already exist
db = openOrCreateDatabase("Mydb", MODE_PRIVATE, null);
// create new table if not already exist
db.execSQL("create table if not exists pendingdatatbl(Id integer
primary key autoincrement,Siteid varchar, ToggleStatus
varchar, ImagePath varchar,LoginTime varchar,LogoutTime
varchar,LatLong varchar)");
dbcount = (int) DatabaseUtils.queryNumEntries(db,
"pendingdatatbl");
//Database d = new Database();
frameLayout = (FrameLayout) findViewById(R.id.content_frame);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
// set up the drawer's list view with items and click listener
mDrawerList.setAdapter(new ArrayAdapter<String>(this,
R.layout.sidemenu_item, listArray));
mDrawerList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
mDrawerList.getChildAt(position).setBackgroundColor(
Color.parseColor("#ff5722"));
openActivity(position);
}
});
// disable ActionBar app icon to behave as action to toggle nav
//drawer
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setDisplayShowHomeEnabled(false);
getActionBar().setHomeButtonEnabled(true);
// orange color of action bar
android.app.ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new
ColorDrawable(Color.parseColor("#ff5722")));
// ActionBarDrawerToggle ties together the the proper
interactions
// between the sliding drawer and the action bar app icon
actionBarDrawerToggle = new ActionBarDrawerToggle(this,
mDrawerLayout,
R.drawable.ic_launcher,
R.string.open_drawer,
R.string.close_drawer)
{
@Override
public void onDrawerClosed(View drawerView) {
getActionBar().setTitle(listArray[position]);
invalidateOptionsMenu();
super.onDrawerClosed(drawerView);
}
@Override
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(getString(R.string.app_name));
invalidateOptionsMenu();
super.onDrawerOpened(drawerView);
}
@Override
public void onDrawerSlide(View drawerView, float
slideOffset) {
super.onDrawerSlide(drawerView, slideOffset);
}
@Override
public void onDrawerStateChanged(int newState) {
super.onDrawerStateChanged(newState);
}
};
mDrawerLayout.setDrawerListener(actionBarDrawerToggle);
isLaunch = false;
openActivity(0);
}
}
protected void openActivity(int position) {
mDrawerLayout.closeDrawer(mDrawerList);
BaseActivity.position = position;
switch (position) {
case 0:
startActivity(new Intent(this, AndroidTabAndListView.class));
break;
case 1:
startActivity(new Intent(this, tab2.class));
break;
case 2:
startActivity(new Intent(this, tab3.class));
break;
default:
break;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (actionBarDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
switch (item.getItemId()) {
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
return super.onPrepareOptionsMenu(menu);
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
dialogOnBackPress();
return true;
}
return super.onKeyDown(keyCode, event);
}
protected void dialogOnBackPress() {
new AlertDialog.Builder(BaseActivity.this)
.setMessage("Are you sure you want to exit?")
.setCancelable(false)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
BaseActivity.this.finish();
Intent intent = new
Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}).setNegativeButton("No", null).show();
}
return super.onCreateOptionsMenu(menu);
}
2.Tab Activity class and child class of sliding menu(But here i
need extend BaseActivity also) :
public class AndroidTabAndListView extends TabActivity{
// TabSpec Names
private static final String INBOX_SPEC = "Inbox";
private static final String OUTBOX_SPEC = "Outbox";
private static final String PROFILE_SPEC = "Profile";
static TextView tvNewNotifications;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
// Inbox Tab
TabSpec inboxSpec = tabHost.newTabSpec("Menu");
// Tab Icon
inboxSpec.setIndicator("Menu",
getResources().getDrawable(R.drawable.ic_action_list_2));
Intent inboxIntent = new Intent(this, InboxActivity.class);
// Tab Content
inboxSpec.setContent(inboxIntent);
// Outbox Tab
TabSpec outboxSpec = tabHost.newTabSpec("Search");
outboxSpec.setIndicator("Search",
getResources().getDrawable(R.drawable.ic_action_search));
Intent outboxIntent = new Intent(this, OutboxActivity.class);
outboxSpec.setContent(outboxIntent);
LayoutInflater inflater = (LayoutInflater)
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View chatTab = inflater.inflate(R.layout.cart_count, null);
// Profile Tab
TabSpec profileSpec = tabHost.newTabSpec("Account");
profileSpec.setIndicator("Account",
getResources().getDrawable(R.drawable.ic_action_user));
Intent profileIntent = new Intent(this, ProfileActivity.class);
profileSpec.setContent(profileIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(inboxSpec); // Adding Inbox tab
tabHost.addTab(outboxSpec); // Adding Outbox tab
tabHost.addTab(profileSpec); // Adding Profile tab
for(int i=0;i<3;i++){
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(
Color.parseColor("#f50057"));
}
}
}
滑动菜单:
标签菜单: