为多个Android应用程序创建模板应用程序 [英] Creating template app for multiple android apps

查看:108
本文介绍了为多个Android应用程序创建模板应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是问题.我想创建几个应用程序,它们看上去都应该完全相同,但是只有一个变量可以更改. 我正在寻找一种创建一个库并将其导入所有其他应用程序的方法,而不是更新很多应用程序,我只能更新该库.

So here is the thing. I want to create few apps, which they all should look exactly the same, but only one variable should change. I'm looking for a way to create one library and to import it in all the other apps, and instead of updating a lot of apps, I would be able to update just the library.

有什么想法可以实现这样的目标吗?也许使用元数据?

Any ideas how such thing can be accomplished? Maybe using meta-data?

谢谢

推荐答案

除了

In addition to CommonsWear's answer, which is correct if you are using Android Studio, what you require can also be achieved in Eclipse - albeit with a little more work.

您需要创建一个库应用程序"(请参见下图),该库应该是您的基本应用程序-即您希望成为所有子应用程序的通用代码库的应用程序.

You'd need to create a 'library application' (see image below) which should be your base application - i.e the app you want to be the common codebase of all the children-apps.

完成后,您应该创建一个使用基础应用程序库的 Android项目(一个子应用)(请参见下面的示例图片)

After that is completed and you should create a new Android project (a child app) that uses the base application library (see example image below)


(来源:
vogella.com )


(source: vogella.com)

子应用程序中的任何值(例如字符串,样式等)都是从父库应用程序 /res文件夹继承的,除非您在子应用 /res文件夹.

Any values in a child app (i.e. strings, styles, etc) are inherited from the parent library app /res folder unless you specify new values in the child app /res folder.

例如如果libraryapp/res/strings.xml包含

<string name="override_me">Hello</string>

childapp/res/strings.xml包含<string name="override_me">Bonjour</string>

然后运行子应用将返回"Bonjour",而不是库中定义的内容.

then running the child app will return "Bonjour" rather than what was defined in the library.

由于子应用程序基本上是一个空项目,没有活动,因此您的子应用程序的清单基本上应该是<manifest>中库 apart 的副本.标签,其中应包含子应用的packageandroid:versionCodeandroid:versionName.它可以使用以下修改后的值启动您的库:

As the child app is basically an empty project without activities, your child app's manifest should basically be a carbon copy of that of the library apart from the <manifest> tag which should contain the child app's package, android:versionCode and android:versionName. It can launch your library with these modified values like this:

 <activity
        android:name="com.example.library.MainActivity"
        android:label="@string/app_name"
        android:launchMode="singleTop">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

作为Eclipse,这个 有点令人费解,但是如果您能够正确设置,它会使创建子应用变得容易快捷(但不像使用Eclipse那样容易) gradle!).

Being Eclipse, this is slightly more convoluted but if you manage to set up correctly, it makes creating child apps quick and easy (but just not as easy as with gradle!).

这篇关于为多个Android应用程序创建模板应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆