extending navigation drawer activity to other activities

前端 未结 6 1101

I\'m trying to create a navigation drawer activity so I can extend that activity and use the menu in all activities by following the answer given in this question Link but m

6条回答
  •  孤街浪徒
    2020-12-10 06:01

    As suggested by oli, you need to call setContentView(R.layout.activity_view) in your main activity.

    BaseActivity's onCreate must be called once content view in Main Activity has been set as shown below :

    public class BaseActivity extends Activity {
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            // REST Navigation drawer initialization
        }
    
    }
    
    
    
    public class MainActivity extends BaseActivity {
    
        protected void onCreate(Bundle savedInstanceState) {
    
            setContentView(R.layout.activity_view);
            super.onCreate(savedInstanceState);
    
            // REST APPLICATION CODE
        }
    }
    

提交回复
热议问题