android:设计一个具有两个页面的程序,第一个页面显示一张封面的图片,第2个页面显示“欢迎进入本系统”,这两个页面之间能相互切换。

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"
    android:gravity="center"
    android:orientation="vertical">
<ImageView
    android:id="@+id/img"
    android:layout_width="360dp"
    android:layout_height="240dp"
    android:layout_centerVertical="true"
    android:src="@drawable/img1"/>
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/t1"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/mButton"
        android:text="@string/b1"
        android:textSize="24sp"
        android:gravity="center"/>

</LinearLayout>

MainActivity.java

package com.example.yanhsama.ex3_3;

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

public class MainActivity extends AppCompatActivity {
    private Button btn;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn=(Button)findViewById(R.id.mButton);
        btn.setOnClickListener(new btnclock());
    }
    class btnclock implements OnClickListener{
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, secondActivity.class);
            startActivity(intent);
        }
    }
}

second.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"
    android:gravity="center">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/t2"
        android:textSize="40sp"/>
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/btn2"
        android:textSize="30sp"/>

</LinearLayout>

secondActivity.java

package com.example.yanhsama.ex3_3;

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

public class secondActivity extends AppCompatActivity {
    Button btn2;
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second);
        btn2=(Button)findViewById(R.id.button2);
        btn2.setOnClickListener(new btnclock());
    }
    class  btnclock implements View.OnClickListener{
        public void onClick(View v){
            Intent intent2=new Intent(secondActivity.this,MainActivity.class);
            startActivity(intent2);
        }
    }
}

strings.xml

<resources>
    <string name="app_name">ex3_3</string>
    <string name="t1">切换页面</string>
    <string name="t2">欢迎进入本系统</string>
    <string name="b1">切换到另一页面</string>
    <string name="btn2">切换到原来的页面</string>
</resources>

AndroidMainfest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.yanhsama.ex3_3">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        </activity>
        <activity
            android:label="@string/app_name"
            android:name=".secondActivity"/>
    </application>

</manifest>

效果截图
在这里插入图片描述
在这里插入图片描述

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值