Android Kua Project Call

Source: Internet
Author: User

Project A is made into Android Library project.

Set up project A, right-->properties->android, select the IS library item, and apply. Set Project B, right-->properties->android, in the library, click the Add button to add a project, and then apply. The resources and code in A are introduced in B at this point, and these resources and code can be called directly. It is important to note that because a is no longer a complete Android application, it is a class library project, so there are some things that need to be configured in B. For example, a in the Lib library reference, B will also be added to the Lib library, such as the contents of the Androidmanifest.xml file in a, in the B androidmanifest.xml file should also be added ...

If you do not need to reference a project's resource files, you just have to get the jar file, set up project A, right-click->properties->android, select the IS library item, and apply. A jar file can be obtained from the bin directory of the A project, which is directly referenced in the Libs directory in Project B. Cases:

 PackageCom.example.titlebar;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.view.Window;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.Button;ImportAndroid.widget.TextView;ImportAndroid.widget.Toast; Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Requestwindowfeature (window.feature_no_title);//hide the original titleSetcontentview (R.layout.activity_main); }}

Package Com.example.titlebar;

Import android.app.Activity;
Import Android.content.Context;
Import Android.util.AttributeSet;
Import Android.view.LayoutInflater;
Import Android.view.View;
Import Android.widget.Button;
Import Android.widget.LinearLayout;
Import Android.widget.Toast;

public class Factivity extends LinearLayout {

Public factivity (context context, AttributeSet Attrs) {
Super (context, attrs);
Layoutinflater.from (context). Inflate (R.layout.biaoti, factivity.this);
TODO auto-generated Constructor stub
Button Backbutton = (button) Findviewbyid (r.id.img);
Button Edbutton = (button) Findviewbyid (R.ID.IMG1);
Backbutton.setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (View v) {
TODO auto-generated Method Stub
(Activity) GetContext ()). Finish ();//And GetContext () gets this, which is equivalent to This.finish (),
In fact, we are in the activity of direct finish () is a shorthand
}
});

Edbutton.setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (View v) {
TODO auto-generated Method Stub
Toast.maketext (GetContext (), "Edit a Ad", Toast.length_short)
. Show ();
}
});
}

}

<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:paddingbottom= "@dimen/activity_vertical_margin"Android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingright= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"Tools:context= "Com.example.titlebar.MainActivity" > <!--<include layout= "@layout/biaoti"/>--<com.example.titlebar.FActivity android:layout_width= "Match_parent"Android:layout_height= "Match_parent" > </com.example.titlebar.FActivity></RelativeLayout>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:background= "#000000"android:baselinealigned= "true" > <Button Android:id= "@+id/img"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_gravity= "Center"Android:layout_margin= "5dip"Android:background= "@drawable/blue_selector"Android:text= "Back"/> <TextView Android:id= "@+id/text"Android:layout_width= "0DP"Android:layout_height= "50DP"android:layout_gravity= "Center"Android:layout_weight= "1"Android:background= "@drawable/ic_dog"android:gravity= "Left|center"Android:text= "Hello"android:textsize= "25sp"/> <Button Android:id= "@+id/img1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_gravity= "Center"Android:layout_margin= "5dip"Android:background= "@drawable/blue_selector"Android:text= "Edit"/></linearlayout>

Right click on the item click Proterties, then click Android, Tick islibrary.

Click Apply

Then the new key is a project test, the same right click on the project click Proterties, then click on Android, click Add, this will appear a titlebar; then apply.

<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:paddingbottom= "@dimen/activity_vertical_margin"Android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingright= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"Tools:context= "Com.example.test.MainActivity" > <com.example.titlebar.FActivity android:layout_width= "Match_parent"Android:layout_height= "Match_parent" > </com.example.titlebar.FActivity></RelativeLayout>
 Packagecom.example.test;Importandroid.support.v7.app.ActionBarActivity;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.view.Window; Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Requestwindowfeature (Window.feature_no_title);    Setcontentview (R.layout.activity_main); } @Override Public BooleanOncreateoptionsmenu (Menu menu) {//inflate the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (R.menu.main, menu); return true; } @Override Public Booleanonoptionsitemselected (MenuItem item) {//Handle Action Bar item clicks here. The Action Bar would//automatically handle clicks on the Home/up button, so long//As you specify a the parent activity in Androidmanifest.xml.        intID =Item.getitemid (); if(id = =r.id.action_settings) {            return true; }        return Super. onoptionsitemselected (item); }}

Android Kua Project Call

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.