-1

I want to create DrawerLayout Dynamically without any xml files just from Code i found some examples to make items Dynamically but i want to create everything Dynamically not only items can i do that? Please help me

MSAG
  • 31
  • 5
  • 1
    Create an instance of `DrawerLayout` using a suitable constructor. Add children to it with appropriate settings for gravity and such. Add the `DrawerLayout` to your view hierarchy (e.g., pass it to `setContentView()`). What have you tried, and what specific problems have encountered? – CommonsWare Aug 21 '17 at 18:09

1 Answers1

0

I found code run

   DrawerLayout drawerLayout;
    FrameLayout drawerPane;
    LinearLayout content;
    //-
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        //-----------------------------
        content = new LinearLayout(this);
        content.SetBackgroundColor(Color.White);
        //-----------------------------
        drawerPane = new FrameLayout(this);
        drawerPane.SetForegroundGravity(GravityFlags.Start);
        drawerPane.Clickable = true;
        drawerPane.SetBackgroundColor(Color.Red);
        //-
        ListView myList = new ListView(this);
        myList.ChoiceMode = ChoiceMode.Single;
        myList.Adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, new List<string>() { "Item #1", "Item #2", "Item #3" });
        drawerPane.AddView(myList, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent));
        //-----------------------------
        drawerLayout = new DrawerLayout(this);
        drawerLayout.AddView(content, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent));
        drawerLayout.AddView(drawerPane, new DrawerLayout.LayoutParams(240, DrawerLayout.LayoutParams.MatchParent, (int)GravityFlags.Start));
        //-----------------------------
        SetContentView(drawerLayout);
    }
MSAG
  • 31
  • 5