文章标题

显示启动Activity

package com.example.mypractise;

import android.content.ComponentName;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
private Button mButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button mButton= (Button) findViewById(R.id.button);
    mButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //此处是按钮的点击事件
            //显示启动Activity,用Intent六大属性之一的Compenont
            Intent intent=new Intent();
            intent.setComponent(new ComponentName(MainActivity.this,SecActivity.class));
            startActivity(intent);
        }
    });

}

}

你可能感兴趣的:(文章标题)