[初学安卓]安卓页面跳转android.content.Intent运用

package com.example.myapplication

import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.example.myapplication.ui.theme.MyApplicationTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MyApplicationTheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    Greeting("页面1")
                }
            }
        }
        val intent = Intent(this, Main2Activity::class.java)//注释2
        startActivity(intent)
    }
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
    Text(
        text = "Hello $name!",
        modifier = modifier
    )
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    MyApplicationTheme {
        Greeting("Android")
    }
}

核心

val intent = Intent(this, Main2Activity::class.java)//注释2
        startActivity(intent)

package com.example.myapplication

import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.example.myapplication.ui.theme.MyApplicationTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MyApplicationTheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    Greeting("页面2")
                }
            }
        }
        val intent = Intent(this, Main2Activity::class.java)//注释2
        startActivity(intent)
    }
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
    Text(
        text = "Hello $name!",
        modifier = modifier
    )
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    MyApplicationTheme {
        Greeting("Android")
    }
}

注册:

相关推荐

  1. uniapp 到应用设置等页面

    2024-05-13 18:14:03       24 阅读
  2. 应用市场APP详情页的方式

    2024-05-13 18:14:03       32 阅读
  3. 小程序两次 iOS不会的解决方案

    2024-05-13 18:14:03       35 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-05-13 18:14:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-05-13 18:14:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-05-13 18:14:03       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-05-13 18:14:03       20 阅读

热门阅读

  1. echarts 社区网站

    2024-05-13 18:14:03       13 阅读
  2. 奇安信网络安全实习一面

    2024-05-13 18:14:03       11 阅读
  3. 神经网络有哪些算法

    2024-05-13 18:14:03       10 阅读
  4. 安卓CoordinatorLayout研究

    2024-05-13 18:14:03       14 阅读