创建library供多个工程共享代码、资源是非常常见的需求,网上这种资料非常少,基本上都是讲创建java工程,然后export,这种方式缺点非常多,大家可以自己google一下。本文着重介绍如何创建Android library,并且在工程中使用此library提供的资源,具体步骤如下:1. 创建一个Android工程,命名为MyLib2. 进入工程设置选中Is Library
3. 创建另一个Android工程,命名为MyProj
4. 进入工程设置,添加MyLib5. 在MyProj的AndroidManifest.xml中加入对library中activity的引用<activity android:name="net.devdiv.mylib.MyLib" />6. 由于编译后library中的资源和引用它的project资源是合并在一起的,为了避免重名问题,需要对library中资源进行重命名1). 把main.xml改为mylib.xml,同时修改MyLib.java代码setContentView(R.layout.mylib);2). strings.xml修改为<?xml version="1.0" encoding="utf-8"?><resources> <string name="mylibhello">String fetched from lib!</string> <string name="mylib_app_name">MyLib</string></resources>7. 在MyProj中引用MyLib的资源package net.devdiv.myproj;import android.app.Activity;import android.os.Bundle;import android.widget.TextView;import net.devdiv.mylib.*;import android.content.Intent;public class MyProj extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView tv = (TextView)findViewById(R.id.myprojtext); tv.setText(R.string.mylibhello); Intent
it = new Intent(this, MyLib.class); startActivity(it); }}
转载自:http://www.devdiv.com/Android-_android_library_-thread-36947-1-1.html
分享到:
相关推荐
Android使用android-beacon-library接收beacon
简单介绍了如何创建属于自己的library,给别人使用。以便以后公用资源。
Android创建Library Project(库项目)与引用操作,演示案例与相关基本操作
混淆打包Android library工程的混淆配置文件
Sharp is a Scalable Vector Graphics (SVG) implementation for Android. It facilitates loading vector graphics as SharpDrawables, and can effectively be used wherever a conventional image would be ...
EZCam is an Android library that simplifies the use of Camera 2 API for a basic usage. Dependencie Add the following line in your gradle dependencies : compile 'me.aflak.libraries:ezcam:X.X' Or if you...
Android Beacon Library An Android library providing APIs to interact with beacons. Please visit the project website for how to use this library. IMPORTANT: By default, this library will only detect ...
android library jar文件混淆
Android Design Support Library v28 控件使用demo Android Design Support Library v28 控件使用demo
Android In-App Billing v3 Library:开发者通过Android v3 API轻松处理应用程序支付问题
Library: BibTeX on Android License: Library is free software published under the GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007. Build (for dummies): Install and set up the Android SDK. ...
android beacon 开发库 可以放心使用,里面包含源代码和测试代码
Android Studio中多项目共享Library Demo
eclipse可用的Android Support Percent Library库,将项目导入eclipse,依赖该项目即可.PercentLinearLayout的编写请自行参考博文http://blog.csdn.net/sbsujjbcy/article/details/46693999
android support library包含support v4,support v7等android兼容库
SDK Manager中Extras下没有Android Support Library.docx
该文件夹是Extras/Android Support Library 的解压包 使用方法:必须先用sdk manager.exe安装了其他的依赖包后,再使用(不然找不到extra文件夹)。 直接复制该文件夹到Android sdk目录下的extras/android 下即可 ...
android support library 23android support library 23android support library 23android support library 23android support library 23android support library 23android support library 23android support ...
下载后,解压出来就是一个包含很多内容的support文件夹,将support文件夹复制到/sdk/extras/android文件夹下即可,这时SDK Manager 中 Extras列表下就显示了Android Support Library
解决SDK Tools下没有Android Support Library的问题,包含support v4,support v7等android兼容库,内含操作说明