如何从 android 库 activity 中的主应用程序扩展 class?
How to extend a class from main application in an android library activity?
我使用了这个答案:Same Navigation Drawer in different Activities 来实现在所有活动中显示的导航抽屉。
我不确定这是否是正确的方法,但目前我有一个主应用程序,它包含一些活动并在 BaseActivity
中实现 NavigationDrawer
。
我想首先创建许多 android 库项目,这些项目将包含 activities/fragments 和它们自己的逻辑。所以现在,除了主应用程序之外,我还创建了一个 android 库项目,我可以从主应用程序(从 NavigationDrawer
)成功启动它的活动之一。
问题是我无法让它扩展 BaseActivity
,因此 NavigationDrawer
没有显示。
所以,目前在主应用程序中,我有:
activity_main.xml // it is the launcher activity
activity_one.xml
activity_two.xml
MainActivity.java
OneActivity.java
TwoActivity.java
效果很好。现在我想将库项目添加到游戏中,其中我有:
activity_three.xml
ThreeActivity.java
现在的问题是,在库项目中,我无法像这样从 BaseActivity
扩展:
public class ThreeActivity extends BaseActivity{ // <-- There's an error here: Cannot resolve symbol 'BaseActivity'
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_three);
}
}
有没有人有任何建议如何做到这一点?
我是否应该创建另一个包含 BaseActivity
和导航抽屉的库项目?
Should I just create another library project that has the BaseActivity and the navigation drawer ?
要么,要么删除所有库并将所有内容移至一个项目中。库不能从 类 从 使用 库的项目继承。不过,库可以从 类 从库本身所依赖的项目继承。
因此,app/
模块可能依赖于 three/
库(具有 ThreeActivity
),而后者又依赖于 base/
库(具有 BaseActivity
).
我使用了这个答案:Same Navigation Drawer in different Activities 来实现在所有活动中显示的导航抽屉。
我不确定这是否是正确的方法,但目前我有一个主应用程序,它包含一些活动并在 BaseActivity
中实现 NavigationDrawer
。
我想首先创建许多 android 库项目,这些项目将包含 activities/fragments 和它们自己的逻辑。所以现在,除了主应用程序之外,我还创建了一个 android 库项目,我可以从主应用程序(从 NavigationDrawer
)成功启动它的活动之一。
问题是我无法让它扩展 BaseActivity
,因此 NavigationDrawer
没有显示。
所以,目前在主应用程序中,我有:
activity_main.xml // it is the launcher activity
activity_one.xml
activity_two.xml
MainActivity.java
OneActivity.java
TwoActivity.java
效果很好。现在我想将库项目添加到游戏中,其中我有:
activity_three.xml
ThreeActivity.java
现在的问题是,在库项目中,我无法像这样从 BaseActivity
扩展:
public class ThreeActivity extends BaseActivity{ // <-- There's an error here: Cannot resolve symbol 'BaseActivity'
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_three);
}
}
有没有人有任何建议如何做到这一点?
我是否应该创建另一个包含 BaseActivity
和导航抽屉的库项目?
Should I just create another library project that has the BaseActivity and the navigation drawer ?
要么,要么删除所有库并将所有内容移至一个项目中。库不能从 类 从 使用 库的项目继承。不过,库可以从 类 从库本身所依赖的项目继承。
因此,app/
模块可能依赖于 three/
库(具有 ThreeActivity
),而后者又依赖于 base/
库(具有 BaseActivity
).