如何抽屉式导航栏添加到应用程序中所有的活动?有的、应用程序、抽屉式

2023-09-13 00:15:51 作者:白衣执笔画浮生

请告诉我有效的方式来增加抽屉式导航栏上的所有活动?我不想重复$ C $下导航抽屉中的所有活动和布局。是否有可能以某种方式来添加导航。抽屉里BaseActivity(自定义类),然后所有其他活动将延长BaseActivity序有抽屉式导航栏?

解决方案   

是否有可能以某种方式来添加导航。抽屉里BaseActivity(自定义类),然后所有其他活动将延长BaseActivity序有抽屉式导航栏?

是的,这是definitly走最彻底的方法。

 公共BaseActivity延伸活动{
    @覆盖
    保护无效的onCreate()
        super.onCreate(); //调用Activity.onCreate()
        //设置你的抽屉式导航
}

公共FirstActivity扩展BaseActivity {
    @覆盖
    保护无效的onCreate()
        super.onCreate(); //将调用BaseActivitiy.onCreate()
        //做一下FirstActivity

}

公共SecondActivity扩展BaseActivity {
    @覆盖
    保护无效的onCreate()
        super.onCreate(); //将调用BaseActivitiy.onCreate()
        //做一下SecondActivity
}
 

拼搏将成为布局。有一个在baselayout与一个占位符的内容视图(活动的可见部分)的BaseActivity。对于所有其他Activitys使用此布局,包括你的内容的浏览。

Whats the efficient way to add Navigation Drawer on all the activities? I don't want to repeat the code for Navigation Drawer in all the activities and their layouts. Is it possible somehow to add Nav. Drawer in BaseActivity(custom class) and then every other activity will extend BaseActivity inorder to have the Navigation Drawer ?

解决方案 在建程序中创建的小程序如何设置底部导航栏

Is it possible somehow to add Nav. Drawer in BaseActivity(custom class) and then every other activity will extend BaseActivity inorder to have the Navigation Drawer ?

Yes this is definitly the cleanest way to go.

public BaseActivity extends Activity {
    @Override
    protected void onCreate()
        super.onCreate(); // calls Activity.onCreate()
        // setup your Navigation Drawer
}

public FirstActivity extends BaseActivity {
    @Override
    protected void onCreate()
        super.onCreate(); // will call the BaseActivitiy.onCreate()
        // do something in the FirstActivity

}

public SecondActivity extends BaseActivity {
    @Override
    protected void onCreate()
        super.onCreate(); // will call the BaseActivitiy.onCreate()
        // do something in the SecondActivity
}

The "hard work" will be the layouts. Have one baseLayout for the BaseActivity with a place holder for the Content View (the visible part of the Activities). For all other Activitys use this layout and include your Content View.