美文网首页
安卓之活动1

安卓之活动1

作者: bluewind1230 | 来源:发表于2018-01-18 20:07 被阅读0次

    创建活动:


    image.png
    activity_main.xml:
    
    
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context="bluelesson.com.my_acitivty_launchmode.MainActivity">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="50sp"
            android:text="第一个界面"
           />
    
        <Button
            android:textSize="20sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="onClickMy"
            android:text="创建自己"/>
        <Button
            android:textSize="20sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="onClick2"
            android:text="创建第二个界面"/>
    </LinearLayout>
    
    
    activity_main2.xml:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context="com.example.bluelesson.my_activity00.Main2Activity">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="50sp"
            android:text="第二个界面"
            />
    
        <Button
            android:textSize="20sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="onClickMy"
            android:text="创建自己"/>
        <Button
            android:textSize="20sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="onClick1"
            android:text="创建第一个界面"/>
    
    
    </LinearLayout>
    
    
    MainActivity:
    package com.example.bluelesson.my_activity00;
    
    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    
    public class MainActivity extends AppCompatActivity {
    private  String  TAG = "MainActivity";
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            Log.e(TAG,"onCreate");//打印错误信息
        }
        public void onClickMy(View view){
            Intent intent = new Intent(MainActivity.this,MainActivity.class);
            startActivity(intent);
        }
    
        public  void onClick2(View view){
            Intent intent = new Intent(MainActivity.this,Main2Activity.class);
            startActivity(intent);
    
        }
            //停止
    
        @Override
        protected void onStop() {
            super.onStop();
            Log.e(TAG,"onStop");
        }
        //销毁
    
    
        @Override
        protected void onDestroy() {
            super.onDestroy();
            Log.e(TAG,"onDestroy");
        }
    
        @Override
        protected void onStart() {
            super.onStart();
            Log.e(TAG,"onStart");
        }
    
        @Override
        protected void onRestart() {
            super.onRestart();
            Log.e(TAG,"onRestart");
        }
    
        @Override
        protected void onPause() {
            super.onPause();
            Log.e(TAG,"onPause");
    
        }
    
        @Override
        protected void onResume() {
            super.onResume();
            Log.e(TAG,"onResume");
        }
    }
    
    
    Main2Activity:
    package com.example.bluelesson.my_activity00;
    
    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.MotionEvent;
    import android.view.View;
    
    public class Main2Activity extends AppCompatActivity {
        private String TAG = "Main2Activity";
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main2);
            Log.e(TAG,"onCreate");
        }
        //创建自己
        public void onClickMy(View view){
           Intent intent = new Intent(Main2Activity.this,Main2Activity.class);
            startActivity(intent);
        }
    
    
    //创建第一个界面
    public void onClick1(View view) {
        Intent intent = new Intent(Main2Activity.this,MainActivity.class);
        startActivity(intent);
    }
    
        //停止
        @Override
        protected void onStop() {
            super.onStop();
            Log.e(TAG,"onStop");
        }
    
        //销毁
        @Override
        protected void onDestroy() {
            super.onDestroy();
            Log.e(TAG,"onDestroy");
        }
    
        @Override
        protected void onRestart() {
            super.onRestart();
            Log.e(TAG,"onRestart");
        }
    
        @Override
        protected void onStart() {
            super.onStart();
            Log.e(TAG,"onStart");
        }
    
        @Override
        protected void onPause() {
            super.onPause();
            Log.e(TAG,"onPause");
        }
    
    
        @Override
        protected void onResume() {
            super.onResume();
            Log.e(TAG,"onResume");
        }
    
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            Log.e(TAG,"onTouchEvent");
            return super.onTouchEvent(event);
        }
    }
    
    
    

    相关文章

      网友评论

          本文标题:安卓之活动1

          本文链接:https://www.haomeiwen.com/subject/jlzwoxtx.html