0

I used this link to create navigation drawer in my app. the question is :is there any way to create a basic activity witch have this drawer and extend other activity from this? i read this but all these links used DrawerLayout not Fragment Navigation Drawer and i can not use them. Is there any tutorial to solve my problem?

Community
  • 1
  • 1
MSepehr
  • 890
  • 2
  • 13
  • 36

1 Answers1

0

Here is what I do :

I create an abstrac class called RootActivity that extends Activity and which inflate the layout with the Drawer. This class has an abstract method createPage in which you will inflate your activity layout.

Here is the basic code for the RootActivity :

public abstract class RootActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.yourRootlayout); //The root layout wich contain your Drawer

        /**
         * This FrameLayout is used has a container for your activity
         * layout as you would do with a fragment container.
         */
        FrameLayout container = (FrameLayout)findViewById(R.id.yourContainer);

        View childActivityLayout = createPage(savedInstanceState);
        if (childActivityLayout != null) {
            container.addView(childActivityLayout);
        }
    }

    public abstract View createPage(Bundle saveInstanceState);
}

And here is how you extend this root class :

public class ExampleActivity extends RootActivity {
    @Override
    public View createPage(Bundle saveInstanceState) {
        View rootView = ...
        //Inflate your layout
        return rootView;
    }
}
Gaël
  • 25
  • 1
  • 6