android - 如何在不同的包中定义 Activity

标签 android

我已将我的应用程序分成几个。我的一些扩展 Activity 的类位于 com.tmt.app 下,另一个 ActivityDialogs 包中>。这两个包都位于 src 文件夹下,我注意到在我的 Manifest 文件中我指定了这样的包名称:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tmt.app"
android:versionCode="1"
android:versionName="1.0" >

表示这个manifest与包com.tmt.app相关,相关类定义如下:

<activity
        android:name=".PasswordDialog"
        android:theme="@style/AboutTheme"
        android:screenOrientation="portrait" >
    </activity>

表示类PasswordDialogcom.tmt.app包中

如何指定此类位于包 Dialogs 下?

提前致谢!

最佳答案

假设您有两个包,例如 com.onecom.two。你的 list 看起来像:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.two"
android:versionCode="1"
android:versionName="1.0" >

.......

<activity
        android:name="com.one.a"
        android:theme="@style/AboutTheme"
        android:screenOrientation="portrait" >
    </activity>

<activity
        android:name=".b"
        android:theme="@style/AboutTheme"
        android:screenOrientation="portrait" >
    </activity>

您需要使用完全限定名称从包外部引用 Activity 。

如果第二个包是像 com.one 和 com.one.two 这样的子包,你将使用:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.one"
android:versionCode="1"
android:versionName="1.0" >

.......

<activity
        android:name=".two.a"
        android:theme="@style/AboutTheme"
        android:screenOrientation="portrait" >
    </activity>

<activity
        android:name=".b"
        android:theme="@style/AboutTheme"
        android:screenOrientation="portrait" >
    </activity>

关于android - 如何在不同的包中定义 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12092599/

相关文章:

android - startActivity 打开图库应用程序但不是可绘制的 jpg 图像(Android 4.0)?

java - "Wiring-up"在android中更改 View 的按钮

Android Studio 3.0 Canary 1 注释处理器错误

按下后退按钮时Android关闭应用程序

Android Unity 插件 list

Android:ListView 条件滚动

android - 在 Android 上以编程方式锁定屏幕

android - 编写一个可以跨设备更新的应用程序

java - Android 无法添加窗口

java - 如何在Android中使用多个where条件从Firebase数据库中获取数据