Create and use an android Library Project
Summary : Create a library for multiple projects to share Code Resources are very common requirements. There is very little such information on the Internet, basically it is about creating a Java project and then export. There are many disadvantages of this method. You can Google it yourself.
This article focuses on how to create an android library and...
Creating a library for multiple projects to share code and resources is a very common requirement. There is very little such information on the Internet, basically it is about creating a Java project and then export. This method has many disadvantages, you can Google it yourself.
This article focuses on how to create an android library and use the resources provided by this library in the project. The steps are as follows:
1. Create an android project named mylib
2. Go to Project Settings and select is library.
3. Create another android project named myproj
4. Go to Project Settings and add mylib
5. Add a reference to the activity in the library to androidmanifest. xml of myproj.
<Activity Android: Name = "net. devdiv. mylib. mylib"/>
6. Because the resources in the library after compilation and the project resources referenced by the library are merged, to avoid duplicate names, you need to rename the resources in the library.
1) Change main. XML to mylib. XML, and modify the mylib. Java code setcontentview (R. layout. mylib );
2). modify 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. reference the resources of mylib in myproj
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);
}< BR >}