gpt4 book ai didi

android - 如何将 Navigation Drawer 添加到应用程序中的所有 Activity?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:18:42 24 4
gpt4 key购买 nike

在所有 Activity 上添加抽屉导航的有效方法是什么?我不想在所有 Activity 及其布局中重复 Navigation Drawer 的代码。是否有可能以某种方式添加导航。 BaseActivity(自定义类)中的抽屉,然后每个其他 Activity 都将扩展 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,并为 Content View( Activity 的可见部分)设置一个占位符。对于所有其他 Activity ,请使用此布局并包括您的内容 View 。

关于android - 如何将 Navigation Drawer 添加到应用程序中的所有 Activity?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18892074/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com