第七周安卓作业

1.

<?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=".MainActivity">

 

    <Button

        android:id="@+id/bt_1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:background="#F2B4FC"

        android:text="显示意图开启界面2"

        android:textSize="20sp"

        android:textColor="#000000"

        android:layout_marginTop="20dp"

        android:layout_marginLeft="10dp"/>

 

</LinearLayout>

复制代码

复制代码

<?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=".Main2Activity">

 

    <Button

        android:id="@+id/bt_2"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:background="#EEA6BF"

        android:text="隐式意图开启界面3"

        android:textSize="20sp"

        android:textColor="#000000"

        android:layout_marginLeft="10dp"

        android:layout_marginTop="20dp"/>

 

</LinearLayout>

package com.example.xie3;

 

import androidx.appcompat.app.AppCompatActivity;

 

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

 

public class MainActivity extends AppCompatActivity {

 

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        Button btn1=(Button)findViewById(R.id.bt_1);

        btn1.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View view) {

                Intent intent=new Intent(MainActivity.this,Main2Activity.class);

                startActivity(intent);

            }

        });

    }

}

package com.example.xie3;

 

import androidx.appcompat.app.AppCompatActivity;

 

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

 

public class Main2Activity extends AppCompatActivity {

 

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main2);

        Button btn2=(Button)findViewById(R.id.bt_2);

        btn2.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View view) {

                Intent intent=new Intent();

                intent.setAction("com.ym.second");

                startActivity(intent);

            }

        });

    }

}

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

<RelativeLayout 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:background="#A5D4FA"

    tools:context=".Main3Activity">

 

    <TextView

        android:id="@+id/tv_1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="界面3"

        android:textSize="20sp"

        android:layout_centerInParent="true"

        android:textColor="#000000"/>

 

</RelativeLayout>

<activity android:name=".Main3Activity">

            <intent-filter>

                <action android:name="com.ym.second" />

 

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

            </intent-filter>

        </activity>

        <activity android:name=".Main2Activity" >

        </activity>

        <activity android:name=".MainActivity">

            <intent-filter>

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

 

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

            </intent-filter>

        </activity>

 

 

 

 

 

2.

<?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"

    android:background="#F7DDFC"

    tools:context=".MainActivity">

 

    <Button

        android:id="@+id/bt_1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:background="#77DDEB"

        android:text="显式意图开启界面2"

        android:textSize="20sp"

        android:layout_marginTop="20dp"

        android:layout_marginLeft="20dp"/>

    <Button

        android:id="@+id/bt_3"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:background="#56AEF5"

        android:text="开启浏览器访问百度"

        android:textSize="20sp"

        android:layout_marginTop="20dp"

        android:layout_marginLeft="20dp"

        android:padding="10dp"

        android:onClick="click3"/>

 

</LinearLayout>

package com.example.xie3;

 

import androidx.appcompat.app.AppCompatActivity;

 

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

 

public class MainActivity extends AppCompatActivity {

 

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        Button btn1=(Button)findViewById(R.id.bt_1);

        btn1.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View view) {

                Intent intent=new Intent(MainActivity.this,Main2Activity.class);

                startActivity(intent);

            }

        });

    }

    public void click3(View view){

        Intent intent=new Intent();

        intent.setAction("android.intent.action.VIEW");

        intent.setData(Uri.parse("http://www.baidu.com"));

        startActivity(intent);

    }

}

 

 3.

<?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"

    android:id="@+id/a_1"

    android:background="#F1B3FC"

    tools:context=".MainActivity">

    <TextView

        android:id="@+id/tv_1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="计算器"

        android:textSize="25dp"

        android:layout_margin="20dp" />

 

    <EditText

        android:id="@+id/et_1"

        android:layout_width="200dp"

        android:layout_height="wrap_content"

        android:hint="请输入一个数"

        android:layout_marginLeft="100dp"

        android:layout_marginRight="100dp"

        android:layout_marginTop="100dp"

        android:inputType="number"

        android:gravity="center"

        android:textSize="20sp"/>

    <EditText

        android:id="@+id/et_2"

        android:layout_width="200dp"

        android:layout_height="wrap_content"

        android:hint="请输入一个数"

        android:layout_marginLeft="100dp"

        android:layout_marginRight="100dp"

        android:inputType="number"

        android:gravity="center"

        android:textSize="20sp" />

    <LinearLayout

        android:id="@+id/a_2"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:orientation="horizontal"

        android:layout_marginTop="20dp"

        android:layout_marginRight="20dp"

        android:layout_marginLeft="20dp">

        <Button

            android:id="@+id/bt_1"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="加(+)"

            android:background="#F7BACE"/>

        <Button

            android:id="@+id/bt_2"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="减(-)"

            android:background="#F7BACE" />

        <Button

            android:id="@+id/bt_3"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="乘(*)"

            android:background="#F7BACE"/>

        <Button

            android:id="@+id/bt_4"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="除(/)"

            android:background="#F7BACE"/>

    </LinearLayout>

    <TextView

        android:id="@+id/tv_2"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="结果="

        android:textSize="25sp"

        android:textColor="#000000"

        android:layout_marginLeft="150dp"

        android:layout_marginRight="150dp"

        android:layout_marginTop="50dp"

        android:gravity="center"/>

 

 

</LinearLayout>

<?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"

    android:id="@+id/a_1"

    android:background="#F1B3FC"

    tools:context=".MainActivity">

    <TextView

        android:id="@+id/tv_1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="计算器"

        android:textSize="25dp"

        android:layout_margin="20dp" />

 

    <EditText

        android:id="@+id/et_1"

        android:layout_width="200dp"

        android:layout_height="wrap_content"

        android:hint="请输入一个数"

        android:layout_marginLeft="100dp"

        android:layout_marginRight="100dp"

        android:layout_marginTop="100dp"

        android:inputType="number"

        android:gravity="center"

        android:textSize="20sp"/>

    <EditText

        android:id="@+id/et_2"

        android:layout_width="200dp"

        android:layout_height="wrap_content"

        android:hint="请输入一个数"

        android:layout_marginLeft="100dp"

        android:layout_marginRight="100dp"

        android:inputType="number"

        android:gravity="center"

        android:textSize="20sp" />

    <LinearLayout

        android:id="@+id/a_2"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:orientation="horizontal"

        android:layout_marginTop="20dp"

        android:layout_marginRight="20dp"

        android:layout_marginLeft="20dp">

        <Button

            android:id="@+id/bt_1"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="加(+)"

            android:background="#F7BACE"/>

        <Button

            android:id="@+id/bt_2"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="减(-)"

            android:background="#F7BACE" />

        <Button

            android:id="@+id/bt_3"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="乘(*)"

            android:background="#F7BACE"/>

        <Button

            android:id="@+id/bt_4"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="除(/)"

            android:background="#F7BACE"/>

    </LinearLayout>

    <TextView

        android:id="@+id/tv_2"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="结果="

        android:textSize="25sp"

        android:textColor="#000000"

        android:layout_marginLeft="150dp"

        android:layout_marginRight="150dp"

        android:layout_marginTop="50dp"

        android:gravity="center"/>

 

 

</LinearLayout>

 

posted @ 2021-10-09 16:58  宿命ゆ偏執  阅读(26)  评论(0编辑  收藏  举报