intent类的不同页面跳转

layout文件 很简单

给Button设置一个点击事件就可以了

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:textSize="50dp"
        android:onClick="tobaidu" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="打开相机"
        android:textSize="50dp"
        android:onClick="tocamera" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="打开相册"
        android:textSize="50dp"
        android:onClick="tophoto" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="打电话"
        android:textSize="50dp"
        android:onClick="tocall" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="发短信"
        android:textSize="50dp"
        android:onClick="tomsg" />
</LinearLayout>

然后就是在Java代码中稍微设置一下就好了

package com.example.secondprogram;

import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    //去浏览器的指定网址页面
    public void tobaidu(View view) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("https://fanyi.baidu.com/?" +
                "aldtype=16047#en/zh/Features%20that%20apply%" +
                "20to%20distribution%20by%20the%20bundle"));
        startActivity(intent);
    }
    //系统自带相机
    public void tocamera(View view) {
        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
        startActivity(intent);
    }
    //系统自带相册
    public void tophoto(View view) {
        Intent intent=new Intent("android.intent.action.PICK");
        intent.setType("image/*");
        startActivity(intent);
    }
    //系统自带电话,且打开时候110已经帮你按好了
    public void tocall(View view) {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        intent.setData(Uri.parse("tel:110"));
        startActivity(intent);
    }
    //打开短信,且收件人和消息已经帮你输入好了,点击发送即可
    public void tomsg(View view) {
        Intent intent = new Intent(Intent.ACTION_SENDTO);
        intent.setData(Uri.parse("smsto:110"));
        intent.putExtra("ssss", "收下");
        startActivity(intent);
        //此处是一个存储工具,可以忽略,SharedPreferences是本地持久存储类
        //SharedPreferences sharedPreferences = 
                        //getSharedPreferences("ss", MODE_PRIVATE);
        //SharedPreferences.Editor editor = sharedPreferences.edit();
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

七qi_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值