Create and use an android Library Project

Source: Internet
Author: User
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 >}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.