How can I use the Navigation Drawer without fragments?

后端 未结 4 1110
不思量自难忘°
不思量自难忘° 2021-02-06 02:32

I\'m trying to follow this tutorial on how to create a Navigation Drawer, but I don\'t want to use Fragments to show new content after the user select an item from the drawer li

4条回答
  •  萌比男神i
    2021-02-06 02:52

    You may use also LayoutInflater class.

    1. Create xml layout file.
    2. Find the View to change using findViewById.
    3. Remove all children from the found View using .removeAllViews() method.
    4. Inflate xml layout content into found View using .inflate() method.

    This is an example:

    LinearLayout layoutToChange = (LinearLayout)findViewById(R.id.layout_to_change);
    layoutToChange.removeAllViews();
    
    LayoutInflater inflater = LayoutInflater.from(this);
    LinearLayout newLayout = (LinearLayout)inflater.inflate(R.layout.new_layout, null);
    
    layoutToChange.addView(newLayout);
    

提交回复
热议问题