I have an app that is using tabHost menu and I need to change it, because the menu items is growing and they don't fit in the current menu. My classes are extending FragmentActivity, I want to know if is possible to use Sliding Menu with them or I will need to change all classes to extend Fragment.
Thanks in advance.
If you use jfeinstein10/SlidingMenu in your project, you can implement sliding menu in your FragmentActivity
, as you want.
Refer to How to Integrate this Library into Your Projects:
You can wrap your Activities in a SlidingMenu by constructing it programmatically (
menu = new SlidingMenu(Context context)
) and then calling
menu.attachToActivity(Activity activity, SlidingMenu.SLIDING_WINDOW | SlidingMenu.SLIDING_CONTENT)
.
SLIDING_WINDOW
will include the Title/ActionBar in the content section of the SlidingMenu, whileSLIDING_CONTENT
does not. You can check it out in the example app AttachExample Activity.
SampleListFragment
which represent your menu, and add to your activity.define a fragment container layout fragment_menu.xml
:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
call menu.setMenu(R.layout.fragment_menu);
to add the fragment container view to your activity,
Lastly, add your SampleListFragment
to your activity's fragment manager:
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragmentContainer, new SampleListFragment())
.commit();
In this way, you got a sliding menu in your fragment activity. That's all.