android – 如何将Navigation Drawer添加到应用程序中的所有活动?

什么是在所有活动上添加导航抽屉的有效方法?我不想在所有活动及其布局中重复导航抽屉的代码.有可能以某种方式添加导航. BaseActivity中的抽屉(自定义类)然后每个其他活动都会扩展BaseActivity以便拥有导航抽屉?

解决方法

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 ?

是的,这绝对是最干净的方式.

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
}

“努力工作”将是布局.为BaseActivity提供一个baseLayout,其中包含内容视图的占位符(活动的可见部分).对于所有其他活动,请使用此布局并包含您的内容视图.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...