Android第七周作业

1.

<?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"
    tools:context=".MainActivity">
 
    <Button
        android:id="@+id/bt_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
 
        android:text="显式意图开启界面2"/>
    <Button
        android:id="@+id/bt_2"
        android:layout_below="@id/bt_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
 
        android:text="隐式意图开启界面3"/>
 
</RelativeLayout>
<?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=".Main2Activity">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
       android:textSize="20dp"
        android:text="界面2"/>
</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"
    tools:context=".Main3Activity">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20dp"
        android:text="界面3"/>
</LinearLayout>
package com.example.chap9;
 
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.chap9;
 
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.zqj.second");
                startActivity(intent);
            }
        });
    }
}

 

 2.

import androidx.appcompat.app.AppCompatActivity;
 
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.content.Intent;
import android.os.Bundle;
 
public class MainActivity extends AppCompatActivity {
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
 
 
 
        public void onClick(View v){
            Intent intent= new Intent();
            intent.setAction("android.intent.action.VIEW");
            intent.setData(Uri.parse("http://www.baidu.com"));
            startActivity(intent);
        }
}
package com.example.work4_1;
 
import androidx.appcompat.app.AppCompatActivity;
 
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.content.Intent;
import android.os.Bundle;
 
public class MainActivity extends AppCompatActivity {
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
 
 
 
        public void onClick(View v){
            Intent intent= new Intent();
            intent.setAction("android.intent.action.VIEW");
            intent.setData(Uri.parse("http://www.baidu.com"));
            startActivity(intent);
        }
}
<?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">
 
 
    <Button
 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="打开百度"
        android:layout_gravity="center"
        android:onClick="onClick"/>
 
 
</LinearLayout>

 

 3.

<?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"
    tools:context=".MainActivity">
 
    <EditText
        android:id="@+id/et1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:gravity="center"
        android:textSize="50dp"/>
    <EditText
        android:id="@+id/et2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:layout_below="@id/et1"
        android:gravity="center"
        android:textSize="50dp"/>
    <Button
        android:id="@+id/add"
        android:layout_width="200px"
        android:layout_height="200px"
        android:text="+"
        android:textSize="50dp"
        android:layout_below="@id/et2"
        android:layout_marginTop="80dp"
        android:onClick="add"/>
    <Button
        android:id="@+id/reduce"
        android:layout_width="200px"
        android:layout_height="200px"
        android:text="-"
        android:textSize="50dp"
        android:layout_below="@id/et2"
        android:layout_toRightOf="@id/add"
        android:layout_marginTop="80dp"
        android:layout_marginLeft="30dp"
        android:onClick="reduce"/>
    <Button
        android:id="@+id/ride"
        android:layout_width="200px"
        android:layout_height="200px"
        android:text="*"
        android:textSize="50dp"
        android:layout_below="@id/et2"
        android:layout_toLeftOf="@id/except"
        android:layout_marginTop="80dp"
        android:onClick="ride"/>
    <Button
        android:id="@+id/except"
        android:layout_width="200px"
        android:layout_height="200px"
        android:text="/"
        android:textSize="50dp"
        android:layout_below="@id/et2"
        android:layout_alignParentRight="true"
        android:layout_marginTop="80dp"
        android:layout_marginLeft="30dp"
        android:onClick="except"/>
<!--        android:layout_toRightOf="@id/ride"-->
 
 
    <TextView
        android:id="@+id/tx1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="结果是:"
        android:textSize="50dp"
        android:layout_below="@id/add"
        android:layout_marginTop="80dp"
         />
    <TextView
        android:id="@+id/tx2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=""
        android:textSize="50dp"
        android:layout_below="@id/add"
        android:layout_toRightOf="@id/tx1"
        android:layout_marginTop="80dp"
        />
 
</RelativeLayout>
import androidx.appcompat.app.AppCompatActivity;
 
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
 
public class MainActivity extends AppCompatActivity {
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
 
 
    public void add(View v){
        String num1=((EditText)(findViewById(R.id.et1))).getText().toString();
        String num2=((EditText)(findViewById(R.id.et2))).getText().toString();
        int n1=Integer.parseInt(num1);
        int n2=Integer.parseInt(num2);
        TextView tx2=(TextView)findViewById(R.id.tx2);
        int sum = n1+n2;
        tx2.setText(String.valueOf(sum));
    }
    public void reduce(View v){
        String num1=((EditText)(findViewById(R.id.et1))).getText().toString();
        String num2=((EditText)(findViewById(R.id.et2))).getText().toString();
        int n1=Integer.parseInt(num1);
        int n2=Integer.parseInt(num2);
        TextView tx2=(TextView)findViewById(R.id.tx2);
        int sum = n1-n2;
        tx2.setText(String.valueOf(sum));
    }
    public void ride(View v){
        String num1=((EditText)(findViewById(R.id.et1))).getText().toString();
        String num2=((EditText)(findViewById(R.id.et2))).getText().toString();
        int n1=Integer.parseInt(num1);
        int n2=Integer.parseInt(num2);
        TextView tx2=(TextView)findViewById(R.id.tx2);
        int sum = n1*n2;
        tx2.setText(String.valueOf(sum));
    }
    public void except(View v){
        String num1=((EditText)(findViewById(R.id.et1))).getText().toString();
        String num2=((EditText)(findViewById(R.id.et2))).getText().toString();
        int n1=Integer.parseInt(num1);
        int n2=Integer.parseInt(num2);
        TextView tx2=(TextView)findViewById(R.id.tx2);
        int sum = n1/n2;
        tx2.setText(String.valueOf(sum));
    }
 }

 

posted @ 2021-10-09 15:59  韩世康  阅读(20)  评论(0编辑  收藏  举报