Android知识点汇总

来源:互联网 发布:单片机设计论文 编辑:程序博客网 时间:2024/06/14 07:28

Android入门语法编辑(1.0)

1.在界面中显示以及输入文本信息

1.1.TextView:

显示文本框控件:

android:id:控件的id

android:layout_width:控件的宽度

android:layout_hight:控件的高度

android:text:文本内容

android:textSize:文本大小(单位sp)

android:textColor:文本颜色

android:background:控件背景

1.2.EditText:

输入文本框控件:

android:id:控件的id

android:layout_width:控件的宽度(”wrap_content”包裹实际文本内容,”fill_parent”当前控件铺满父类容器,”match_parent”当前控件铺满父类容器)

android:layout_hight:控件的高度

android:text:文本内容

android:textSize:文本大小

android:textColor:文本颜色

android:background:控件背景

android:hint:输入提示文本

android:inputType:输入文本类型

注:setContentView(R.layout.main.activity)//将布局XML文件引入到activity当中

2.在界面中显示图片

2.1.ImageView:

2.1.1.图片显示控件

1.      android:src=”@drawable/ic_launcher”:内容图像

2.      android:background=”@drawable/ic_launcher:背景图片

3.      android:background=”#00ff00”:RGB颜色

2.1.2.分辨率

根据手机分辨率的不同而自行选择相应的图片

3.按钮Button以及ImageButton

3.1.Button按钮

<Button

android:id=”@+id/button1”

android:layout_width=”image_parent”

android:layout_height=”wrap_content”

android:text=”Button”/>

3.2.ImageButton图片按钮:

android:id=”@+id/imageButton1”

android:layout_width=”match_parent”

android:layout_height=”wrap_content”

android:src=”@drawableabc_ab_share_pack_holo_light/>”

3.2.1.共同特征:

1.  都可以作为一个按钮产生点击事件

2.  都产生明显的点击效果

3.2.2.不同特征:

1.  Button有text的属性,ImageButton则没有

2.  ImageButton有src 属性,Button则没有

注:res-valus-strings.xml

<stringname=”button_name”>登录</string>

android:text=”@string/button_name”/>

4.监听按钮的点击事件

4.1.onClick事件:

1.      通过自身的.setOnClickListener(OnClickListener)添加点击事件

2.      所有的控件都有一个onClick的事件

3.      通过点击事件的监听可以实现点击按钮之后要发生什么动作

4.2.监听事件实现的几种写法:

1.      匿名内部类的实现

2.      独立类的实现

3.      实现接口的方式来实现

4.2.1.匿名内部类监听按钮点击事件:

1.      初始化当前所需控件,如何初始化一个控件?

Private Button loginButton

loginButton=findViewById(R.id.button1);

注:findViewById:返回的是一个View的对象

2.      设置Button的监听器,通过监听器实现我们点击Button要操作的事情

loginButton.setOnClickListener(new Onclicklistener(){

public void onClick(View arg0){

//在当前onClick方法中监听点击Button的动作

System.out.println(“我的Button被点击了”)

}

});

4.2.2.外部类监听点击事件(很少用)

Private Button loginButton

loginButton=(Button) findViewById(R.id.button1);

loginButton.setOnClickListener(new MyOnclicklistener(){

public void onClick(View v){

super.onClick(v);//调用父类的onClick方法

  Toast.makeText(MainActivity.this,”…”,1).show();

}

}

class MyOnClickListener implementsOnClickListener

//OnClickListener是一个接口,不能通过继承来实现{

public void onClick(View v){

log.i(“tag”,”父类的onClicker事件”)

}

4.2.3.接口方式监听按钮点击事件:

public class MainActivity extends Activityimplements OnClickListener{

private ImageButton imgBt;

imgBt=(Button)findViewById(R.id.imageButton1);

imgBt.setOnClickListener(this);

public void onClick(View v){

log.i(“tag”,”第三种方法实现”)

}

}

5.实现动态自动匹配输入的内容

5.1.AutoCompleteTextView概述:

<AutoCompleteTextView

 android:completionThreshold=”3”

 android:id=”@+id/autuCompleteTextView1”

 android:layout_width=”match_parent”

 android:layout_height=”wrap_content”

android:hint=”…”>

</AutoCompleteTextView>

5.1.1.使用AutoCompleteTextView实现自动匹配输送

public class MainActivity extends Activity{

    private AutoCompleteTextView acTextView;

    private String[] res={“beijing1”,”beijing2”,”beijing3”,”shanghai1”,”shanghai2”};

    protected void onCreate(Bundle savedInstanceState){

    super.onCreate(SavedInstanceState);

    setContentView(R.layout.activity_main);

    //初始化控件

    acTextView=(ActoCompleteTextView)findViewById(R.id.autoCompleteTextView1)

    //需要一个适配器

ArrayAdapter<String>adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,res)

//初始化数据源:去匹配文本框中输入的内容

acTextView.setAdapter(adapter);

//将adapter与当前AutoCompleteTextView绑定

    }

5.2.MultiAutoCompleteTextView概述:

5.2.1.功能

可支持选择多个值(在多次输入的情况下),分别用分隔符分开,并且在每个值选中的时候再次输入值时会自动去匹配,可用在发短信,发邮件时选择联系人这种类型中

5.2.2.独特属性:

     Android:completionThreshold=”2”:设置输入多少字符时自动匹配

5.2.3.设置分隔符:

     mtxt.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());

5.3.使用MultiAutoCompleteTextView实现自动匹配输送

public class MainActivity extends Activity{

private MultiAutoCompleteTextView macTextView;

macTextView= (MultiAutoCompleteTextView)findViewById(R.id. MultiAutoCompleteTextView);

macTextView.setAdapter(adapter);//同上

mavTextView.setToKenizer(new MultiAutoCompleteTextView.CommaTokenizer());

//设置以逗号为分隔符为结束的符号

5.4.两者间的区别:

1.      AutoCompleteTextView:作为单个搜索功能

2.      MultiAutoCompleteTextView:作为发送邮件的编辑文本框,可以以分隔符为割点多次匹配

6.使用多状态按钮ToggleButton

6.1.ToggleButton概述:

6.1.1.两种状态:

选中状态和未选中状态,并且需要为不同的状态设置不同的显示文本

6.1.2.属性:

android:checked=”true”

android:textOff=”

android:textOn=”

<!--textOn:true  textOff:false-->

<ToggleButton

  android:textOn=”开”

  android:textOff=”关”

  android:id=”@+id/toggleButton1”

  android:layout_width=”match_parent”

  android:layout_height=”wrap_content”/>

6.2.ToggleButton按钮实现开关效果:

public class MainActivity extends Activityimplements OnCheckedChangedListener{

private ToggleButton tb;

private ImageView img;

protected void onCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

set.ContentView(R.layout.activity_main);

//初始化控件

tb=(ToggleButton)findViewById(R.id.toggleButton1);

img=(ImageView)findViewById(R.id.imageView1);

//给当前tb设置监听器

tb.setOnCheckedChangeListener(this);

public void onCheckedChanged(CompoundButtonbuttonView,boolean isChecked){

//当tb被点击的时候,当前的方法会执行

//buttonView:代表被点击控件的本身

//isChecked:代表被点击的控件的状态

//当点击这个tb的时候,更换img的背景

Img.setBackgroundResource(isChecked?R.drawable.on;R.drawable.off);

7.使用CheckBox实现多选效果

7.1.复选框CheckBox概述:

7.1.1.两种状态:

     选中状态(true),未选中状态(false)

7.1.2.属性:

     android:id=”@+id/checkbox”

     android:layout_width=”wrap_content”

     android:layout_height=”wrap_content”

     android:checked=”false”

     android:text=”男”

7.2.使用CheckBox:

<CheckBox

     android:id=”@+id/checkBox1”

     android:layout_width=”wrap_content”

     android:layout_height=”wrap_content”

     android:text=”篮球”/>

 

public class MainActivity extends Activity {

private CheckBox checkBox;

protected void onCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

set.ContentView(R.layout.activity_main);

//初始化checkBox

checkBox=(CheckBox)findViewById(R.id.checkBox1);

//通过设置checkBox的监听事件来对checkBox是不是被选中

checkBox.setOnCheckedChangeListener(newOnCheckedChangeListener(){

public void onCheckChanged(CompoundButtonbuttonView,boolean isChecked){

//通过onCheckedChanged来监听当前的CheckedBox是否被选中

if(isChecked){

//获得checkBox的文本内容

String text =checkBox.getText().toString();

Log.i(“tag”,text);

}

}

});

8.使用RadioGroupRadioButton实现单选按钮

8.1.RadioGroup:

RadioGroup的一个集合,提供多选一机制

8.2.属性

    android:orientation=(1)”vertical”:垂直排布

                   (2)”horizontal”:水平排布

决定当前RadioGroup中RadioButton以什么形式排布

8.3.使用RadioGroupRadioButton:

<RadioGroup

     android:orientation=”horizonta1”

     android:id=”@+id/radioGroup1”

     android:layout_width=”wrap_content”

     android:layout_height=”wrap_content”>

<RadioButton

     android:id=”@+id/radio0”

     android:layout_width=”wrap_content”

     android:layout_height=”wrap_content”

     android:checked=”true”

     android:text=”男”/>

<RadioButton

     android:id=”@+id/radio0”

     android:layout_width=”wrap_content”

     android:layout_height=”wrap_content”

     android:checked=”true”

     android:text=”女”/>

 

public class MainActivity extends Activity implementsOnCheckedChangeListener {

private RadioGroup rg;

protected void onCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

set.ContentView(R.layout.activity_main);

//初始化rg

rg=(RadioGroup)findViewById(R.id.radioGroup1);

//实现RadioGroup的一个监听事件

rg. setOnCheckedChangeListener(this);}

public void onCheckedChanged(RadioGroupgroup,int checkedId){

switch(checkedId){

case R.id.radio0:

   Log.i(“tag”,”你当前是个男孩”)

break;

case R.id.radio1:

   Log.i(“tag”,”你当前是个女孩”)

break;

default:

break;

}

}

9.五布局之线性布局LinearLayout

9.1.布局概念:

<?xml version="1.0"encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

   android:layout_width="match_parent"

   android:layout_height="match_parent"

   android:orientation="vertical" >

</LinearLayout>

9.2.理解线性布局:

LinearLayout是线性布局控件,它包含的子控件将以横向或竖向的方式排列

9.3.常用属性:

LinearLayout两个常用属性:

1.      android:orientation=”vertical”:该属性决定它的子类控件的排布方式(vertical:垂直;horizontal:水平)

2.      android:gravity=”center”:该属性决定它的子类xy的位置

(常用到的几个属性值:

1.      center_vertical:垂直(y轴)居中

2.      centre_horizontal:水平(x轴)居中)

3.      center:水平垂直都居中

4.      right:子类控件位于当前布局的右边

5.      left:子类控件位于当前布局的左边

6.      button:子类控件位于当前布局的下面

9.4.使用线性布局:

9.4.1.子类控件在LinearLayout中常用到的属性

1. android:layout_gravity=”botton”:指本身在当前父容器的xy的一个位置

2.android:layout_weight=”1”:指本身控件占当前父容器的一个比例

 

<?xml version="1.0"encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

   android:layout_width="match_parent"

   android:layout_height="match_parent"

   android:orientation="vertical"

   >

 

   <Button

       android:id="@+id/button2"

       android:layout_width="match_parent"

       android:layout_height="wrap_content"

       android:layout_weight="1"

       android:text="Button" />

 

   <Button

       android:layout_gravity="center_horizontal"

       android:layout_weight="1"

       android:id="@+id/button1"

       android:layout_width="match_parent"

       android:layout_height="wrap_content"

       android:text="Button" />

  

</LinearLayout>

10.五布局之相对布局RelativeLayout

10.1.理解相对布局:

1. RelativeLayout:是相对布局控件,它包含的子控件将以控件之间的相对位置或者子类控件相对父类容器的位置的方式排布

10.2.使用相对布局:

10.2.1.子类控件在RelativeLayout中常用到的属性(相对父容器的一个位置)

android:layout_alignParentLeft=”true”:子类控件相对当前父类容器靠左边

android:layout_alignParentTop=”true”:子类控件相对父类容器靠上边

android:layout_marginLeft=”41dp”:子类控件距离父类容器左边的距离

android:layout_marginTop=”33dp”:子类控件距离父类容器上边的距离

android:layout_centerInParent=”true”:子类控件相对父类容器即水平居中又垂直居中

android:layout_centerHorizontal=”true”:子类控件相对父类容器水平居中

android:layout_centerVertical=”true”:子类控件相对父类容器垂直居中

10.2.2.子类控件相对子类控件的一个位置

android:layout_below=”@+id/button1”:该控件位于给定id控件的底部

android:layout_toRightOf=”@+id/button1”:该控件位于给定id控件的右边

android:layout_above=”@+id/button1”:该控件位于给定id控件的上面

android:layout_toLeftOf=”@+id/button1”:该控件位于给定控件的走边

android:layout_alignBaseline=”@+id/button1”:该控件的内容与给定id控件的内容在一条线上

android:layout_alignBotton:该控件的底部边缘与给定id控件的底部边缘对齐

android:layout_alignLeft:该控件的左边缘与给定id控件的左边缘对齐

android:layout_alignRight: 该控件的右边缘与给定id控件的右边缘对齐

android:layout_alignTop:该控件的顶部边缘与给定id控件的顶部对齐

11.五布局之帧布局FrameLayout

11.1.FrameLayout:

在这个布局中,所有的子元素都不能被指定放置的位置,他们统统放于这块区域的左上角,并且后面的子元素直接覆盖在前面的子元素之上,将前面的子元素部分和全部遮挡

11.2.FrameLayout的使用:

<?xml version="1.0"encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

   android:layout_width="match_parent"

   android:layout_height="match_parent" >

 <TextView

    android:layout_gravity="center"

    android:background="#785435"

    android:id="@id/textView1"

    android:layout_width="200dp"

    android:layout_height="200dp"

    android:text="第一的页面"/>

 

<TextView

    android:layout_gravity="center"

    android:background="#985764"

    android:id="@id/textView1"

    android:layout_width="150dp"

    android:layout_height="150dp"

    android:text="第二的页面"/>

<TextView

    android:layout_gravity="center"

    android:background="#564238"

    android:id="@id/textView1"

    android:layout_width="100dp"

    android:layout_height="100dp"

    android:text="第三的页面"/>

 

</FrameLayout>

12.五布局之绝对布局AbsoluteLayout

12.1.AbsoluteLayout:

1. AbsoluteLayout:又可叫做坐标布局,可以直接指定子元素的绝对位置(xy)

2.由于手机屏幕尺寸差别比较大,使用绝对定位的适应性会比较差,在屏幕的适配上有缺陷

12.2.子类控件的属性:

android:layout_x=”35dip”:控制当前子类控件的x位置

android:layout_y=”40dp”:控制当前子类控件的y位置

13.五布局之表格布局TableLayout

13.1.TableLayout简介:

TableLayout:表格布局模型以行列的形式管理子控件,每一行为一个TableLayout的对象,当然也可以是一个View的对象

13.2.全局属性:

android:collapseColumns=”1,2”:隐藏从0开始的索引列,列之间必须用逗号隔开:1,2,5

android:shrinkColumns=”1,2”:收缩从0开始的索引列,当可收缩的列太宽(内容过多)不会被挤

出屏幕,列之间必须用逗号隔开:1,2,5,你可以通过”*”代替收缩所有列

注意一列能同时表示收缩和拉伸

android:stretchColumns=”1,2”:拉伸从0开始的索引列,以填满剩下的多余空白空间,列之间必须用逗号隔开:1,2,5,你可以通过”*”代替收缩所有列

注意一列能同时表示收缩和拉伸

13.3.局部属性:

android:layout_column=”1”:该控件显示在第2列

android:layout_span=”2”:该控件占据2列

13.4.使用TableLayout的属性:

<?xml version="1.0"encoding="utf-8"?>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"

   android:layout_width="match_parent"

   android:shrinkColumns="0"

   android:stretchColumns="0,1,2"

   android:layout_height="match_parent" >

 

   <TableRow

       android:id="@+id/tableRow1"

       android:layout_width="wrap_content"

       android:layout_height="wrap_content" >

 

       <Button

           android:id="@+id/button1"

           android:layout_width="wrap_content"

           android:layout_height="wrap_content"

           android:text="@string/text_bt1" />

 

       <Button

           android:id="@+id/button2"

           android:layout_width="wrap_content"

           android:layout_height="wrap_content"

           android:text="Button2" />

 

       <Button

           android:id="@+id/button3"

           android:layout_width="wrap_content"

           android:layout_height="wrap_content"

           android:text="Button3" />

 

   </TableRow>

 

   <TableRow

       android:id="@+id/tableRow2"

       android:layout_width="wrap_content"

       android:layout_height="wrap_content" >

 

       <Button

           android:layout_column="1"

           android:layout_span="2"

           android:id="@+id/button4"

           android:layout_width="wrap_content"

           android:layout_height="wrap_content"

           android:text="Button" />

 

       <Button

           android:id="@+id/button5"

           android:layout_width="wrap_content"

           android:layout_height="wrap_content"

           android:text="Button" />

 

       <Button

           android:id="@+id/button6"

           android:layout_width="wrap_content"

           android:layout_height="wrap_content"

           android:text="Button" />

 

   </TableRow>

 

</TableLayout>

 

14.认识Activity

14.1.认识Activity:

1. Activity:是一个应用程序组件,提供用户与程序交互的界面

2. Android:四大组件:Activity

                 Service

                 BroadcastReceiver

                 Content Provider

3.Activity的创建和使用:继承Android的Activity类

                     重写方法

                     设置显示的布局

                     在AndroidMainfest文件中,注册Activity

14.2.生命周期概述:

onCreate():创建

onStart():运行

onResume():获取焦点

onPause():失去焦点

onStop():暂停

onDestroy():销毁

onRestart():重启

14.3.Activity的生命周期:

1. 活动状态(Active/Running)Activity处于界面最顶端,获取焦点

2. 暂停状态(Paused)Activity失去焦点,但对用户可见

3. 停止状态(Stopped)Activity被完全遮挡,但保留所有状态和成员信息

4. 非活动状态(Killed)Activity被停止

15.使用Intent实现页面跳转

15.1.何为Intent:

Intent可以理解为信使(意图)

由Intent来协助完成Android各个组件之间的通讯

15.2.实现页面之间跳转

1. startActivity(intent):无返回结果的页面跳转

2.startActivityForResult(intent,requestCode):有返回结果的页面跳转

 onActivityResult(int requestCode,int resultCode,Intent data)

 setResult(resultCode,date);

15.3.无返回结果的页面跳转

FActivity.java

packagecom.example.none1;

importandroid.app.Activity;

importandroid.os.Bundle;

importandroid.view.View;

importandroid.widget.Button;

 

public classFActivity extends Activity{

         privateButton bt1;

         privateContext mContext

         protectedvoid onCreate(Bundle savedInstanceState){

                   super.onCreate(savedInstanceState);

                   setContentView(R.layout.factivity);

                   //通过点击bt1实现页面之间的跳转

                   //用startActivity的方法来实现

                   //初始化Intent

                   mContext=this;

                   bt1=(Button)findViewById(R.id.button1_first);

                   //注册点击事件

                   bt1=setOnClickListener(newonClickListener(){

                            publicvoid onClick(View v){

                                     //第一个参数:上下文对象this

                                     //第二个参数:目标文件

                                     Intentintent=new Intent(mContent,SActivity.class);

                                     startActivity(intent);

                   }

         });

         }

}

        

factivity.xml

<?xml version="1.0"encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

   android:layout_width="match_parent"

   android:layout_height="match_parent"

   android:orientation="vertical" >

 

   <Button

        android:id="@+id/button1_first"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:text="第一种启动方式"/>

 

   <Button

        android:id="@+id/button2_second"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="第二种启动方式"/>

 

   <TextView

        android:id="@+id/textView1"

        android:layout_width="matc_parentt"

        android:layout_height="wrap_content"

        android:text="把第二页面回传的数据显示出来"/>

 

</LinearLayout>

 

SActivity.java

packagecom.example.none1;

importandroid.app.Activity;

importandroid.os.Bundle;

 

public classSActivity extends Activity {

         protectedvoid onCreate(Bundle savedInstanceState){

                   super.onCreate(savedInstanceState);

                   setContentView(R.layout.sactivity);

         }

 

}

 

sactivity.xml

<?xml version="1.0"encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

   android:layout_width="match_parent"

   android:layout_height="match_parent"

   android:orientation="vertical" >

 

   <Button

        android:id="@+id/button1"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

       android:text="Button"/>

 

</LinearLayout>

 

Mainfest

<?xml version="1.0"encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

   package="com.example.none1"

   android:versionCode="1"

   android:versionName="1.0" >

 

   <uses-sdk

       android:minSdkVersion="19"

       android:targetSdkVersion="19" />

 

   <application

       android:allowBackup="true"

       android:icon="@drawable/ic_launcher"

       android:label="@string/app_name"

       android:theme="@style/AppTheme" >

       

       </activity>

        <activity

           android:name="com.example.none1.FActivity"

           android:label="@string/app_name" >

           <intent-filter>

                <action android:name="android.intent.action.MAIN"/>

 

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

           </intent-filter>

       </activity>

        <activity

           android:name="com.example.none1.SActivity"

           android:label="@string/app_name" >

          

       </activity>

   </application>

 

</manifest>

15.4.有返回结果的页面跳转

FActivity.java

packagecom.example.none1;

importandroid.app.Activity;

importandroid.os.Bundle;

importandroid.view.View;

importandroid.widget.Button;

 

public classFActivity extends Activity{

         privateButton bt1;

         privateButton bt2;

         privateContext mContext;

         privateTextView tv;

         protectedvoid onCreate(Bundle savedInstanceState){

                   super.onCreate(savedInstanceState);

                   setContentView(R.layout.factivity);

                   //通过点击bt1实现页面之间的跳转

                   //用startActivity的方法来实现

                   //初始化Intent

                   mContext=this;

                   tv=(TextView)findViewById(R.Id.textView1);

                   bt1=(Button)findViewById(R.id.button1_first);

                   bt2=(Button)findViewById(R.id.button2_second)

                   //注册点击事件

                   bt1=setOnClickListener(newonClickListener(){

                            publicvoid onClick(View v){

                                     //第一个参数:上下文对象this

                                     //第二个参数:目标文件

                                     Intentintent=new Intent(mContent,SActivity.class);

                                     startActivity(intent);

                   }

          });

                   //通过startActivityForresult

                   bt2=setOnClickListener(newonClickListener(){

                            publicvoid onClick(View v){

                                     //第一个参数:是Intent对象

                                     //第二个参数:是请求的一个标志

                                     Intentintent=new Intent(mContext,SActivity.class);

                                     //

                                     startActivityForresult(intent,requestCode);

                   }

          });

   }

         //通过startActivityForresult跳转,接收返回数据的方法

         //requestCode:请求的标志

         //resultCode:第二个页面返回的标

         //Intentdata:第二个页面回传的数据

         protectedvoid onActivityResult(int requestCode,int resultCode,Intentdata){

                   super.onActivityResult(requestCode,resultCode, data);

                   if(requestCode==1&&requestCode==2){

                            Stringcontent=data.getStringExtra("data");

                            tv.setText(content);

                   }

         }

}

        

factivity.xml

<?xml version="1.0"encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

   android:layout_width="match_parent"

   android:layout_height="match_parent"

   android:orientation="vertical" >

 

   <Button

        android:id="@+id/button1_first"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:text="第一种启动方式"/>

 

   <Button

        android:id="@+id/button2_second"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="第二种启动方式"/>

 

   <TextView

        android:id="@+id/textView1"

        android:layout_width="matc_parentt"

        android:layout_height="wrap_content"

        android:text="把第二页面回传的数据显示出来"/>

 

</LinearLayout>

 

 

SActivity.java

package com.example.none1;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.widget.Button;

 

publicclassSActivityextendsActivity {

    private Buttonbt;

    private Stringcontent="你好";

    protectedvoid onCreate(BundlesavedInstanceState){

        super.onCreate(savedInstanceState);

        setContentView(R.layout.sactivity);

        //第二个页面什么时候给第一个页面回传数据

        //回传到第一个页面的实际上是一个Intent的对象

        bt=(Button)findViewById(R.id.button1);

        bt.setOnClickListener(newOnClickListener(){

            publicvoid onClick(View v){

                Intentdata=newIntent();

                data.putExtra("data",content);

                setResult(2,data);

                //结束当前页面

                finish();

            }

        });

    }

 

}

 

sactivity.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

   android:layout_width="match_parent"

   android:layout_height="match_parent"

   android:orientation="vertical" >

 

    <Button

        android:id="@+id/button1"

       android:layout_width="match_parent"

       android:layout_height="wrap_content"

        android:text="Button"/>

 

</LinearLayout>

 

MainFest

<?xmlversion="1.0"encoding="utf-8"?>

<manifestxmlns:android="http://schemas.android.com/apk/res/android"

    package="com.example.none1"

    android:versionCode="1"

    android:versionName="1.0">

 

   <uses-sdk

        android:minSdkVersion="19"

        android:targetSdkVersion="19"/>

 

   <application

        android:allowBackup="true"

        android:icon="@drawable/ic_launcher"

        android:label="@string/app_name"

        android:theme="@style/AppTheme">

       

        </activity>

         <activity

           android:name="com.example.none1.FActivity"

           android:label="@string/app_name">

            <intent-filter>

                <actionandroid:name="android.intent.action.MAIN"/>

 

                <categoryandroid:name="android.intent.category.LAUNCHER"/>

            </intent-filter>

        </activity>

         <activity

           android:name="com.example.none1.SActivity"

           android:label="@string/app_name">

          

        </activity>

   </application>

 

</manifest>

16.App签名打包

16.1.Android-App签名打包

1.为了保证每个应该程序开发者的合法

2.防止部分人通过使用相同的PackageName来混淆替换已经安装的程序,从而出现一些恶意窜改

3. 保证我们每次发布的版本的一致性(如自动更新不会因为版本不一致而无法安装)

17.使用SDK开发文档

17.1.Android-使用SDK开发文档

sdk:docs:index.html:Devolop

 

18.搭建Android开发环境

18.1.搭建android应用开发环境需要以下工具

1.      JDK

2.      Eclipse

3.      Android SDK

4.      ADT

19.Android项目结构介绍

19.1.src:

存放Java源代码

19.2.gen:

存放系统自动生成的配置文件

19.3.Android 4.4.2:

该文件夹下包含android.jar文件,这是一个Java归档文件,其中包含构建应用程序所需的所有的Android SDK库(如Views,Controls)和APIs

19.4.assets:

存放资源文件,不会自动生成id 且不会自动占用空间

19.5.bin:

存放应用被编辑后生成的可执行文件(.apk),以及应用用到被打包到apk中的资源文件

19.6.res:

存放应用程序用到的所有资源,如图片布局等等

19.7.drawable:

存放不同密度的图片资源

19.8.layout:

存放布局文件

19.9.valus:

存放字符串,主题,颜色,样式等资源文件

19.10.AndroidMainfest.xml:

清单文件,配置一些与应用程序有关的重要信息,包含包名,权限,程序组件等等

20.1.安装:

百度搜索:android系统怎样安装程序到手机上