第七周作业

1.三个界面,界面1点击按钮使用显式意图开启界面2.
界面2点击按钮隐式意图开启界面3


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    >
<Button
    android:id="@+id/but_1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="显示意图显示界面二"
    android:textSize="25dp"
    android:onClick="click1"/>
</RelativeLayout>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_height="match_parent"
    android:layout_width="match_parent">
    <Button
        android:id="@+id/bit_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="界面二"
        android:textSize="25dp"
        android:layout_centerHorizontal="true"/>
</RelativeLayout>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent">
    <Button
        android:id="@+id/bit_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="界面三"
        android:textSize="25dp"
        android:layout_centerHorizontal="true"/>
</RelativeLayout>









package cn.itcast.chap04;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
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 );

    }
    
   public void click1(View view){
        Intent intent=new Intent( this,Main2Activity.class );
        startActivity( intent );

    }
}

 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_height="match_parent"
    android:layout_width="match_parent">
    <Button
        android:id="@+id/but_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="隐式意图显示界面三"
        android:textSize="25dp"
        android:onClick="click2_3"/>

</RelativeLayout>


package cn.itcast.chap04;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class Main2Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main2 );
    }
    public void click2_3(View view){
        Intent intent=new Intent(  );
        intent.setAction( "start_activity" );
        startActivity( intent );
    }


}


<activity android:name=".Main3Activity">
    <intent-filter>
        <action android:name="start_activity" />

        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>
<activity android:name=".Main2Activity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

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

</activity>

2.在界面1做一个按钮开启浏览器访问百度


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    >
    <Button
        android:id="@+id/but_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="界面一"
        android:textSize="25dp"
       android:layout_centerHorizontal="true"/>
<Button
    android:id="@+id/but_4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="隐式意图打开浏览器"
    android:textSize="25dp"
    android:onClick="click3"
    android:layout_below="@id/but_3"/>
</RelativeLayout>

package cn.itcast.chap04;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
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 );

    }
 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 );
    }



}

 

 

 

posted @ 2021-10-08 14:45  计算机1902张铭麟  阅读(6)  评论(0编辑  收藏  举报