19-10-11 Toast提醒方式,Intent转换

布局文件 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"
    tools:context=".MainActivity">

<Button
<android:id="button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button"/>
</LinearLayout>

新建布局文件activity_intent.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"
    tools:context=".IntentActivity">
<Button
<android:id="button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button2"/>
</LinearLayout>

IntentActivity.java

package com.example.toast;

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

public class IntentActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_intent);
Button button=(Button)findViewById(R.id.button2);
button.setOnClickListener(new View OnclickListener(){
@Override
public void onClick(View v){
Intent intent=new Intent(IntentActivity.this,MainActivity.class);
startActivity(intent);
}

});
}
}

主文件 MainActivity.java

package com.example.toast;

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

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
     Button button=(Button)findViewById(R.id.button1);
      button.setOnclickListener(new View.OnclickListener(){
  @Override
    public void onClick(View v){
Toast.makeText(MainActivity.this,"hello wqsy",Toast.LENGTH_SHORT).show();
Intent intent=new Intent(MainActivity.this,IntentActivity.class);
startActivity(intent);
finish();
}
});

}
}

finish();加上是销毁程序
Intent转换第一页面到第二页面 返回第一页面

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。