Android开发教程Kotlin 1.学习内容
2.Activity之间的跳转
MainActivity
android简单教程ample.kotlinstudy
t.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
class MainActivity : AppCompatActivity() {
var tv_first = findViewById<TextView>(R.id.tv_first)
override fun onCreate(savedInstanceState: Bundle?) {
setContentView(R.layout.activity_main)
tv_first.setOnClickListener{
val intent = Intent(this,SecondActivity::class.java)
intent.putExtra("name","测试传参")
startActivity(intent)
}
}
}
<?xml version="1.0" encoding="utf-8"?>
&straintlayout.widget.ConstraintLayout xmlns:android="schemas.android/apk/res/android" xmlns:app="schemas.android/apk/res-auto"
xmlns:tools="schemas.android/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/tv_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</straintlayout.widget.ConstraintLayout>
SecondActivity
ample.kotlinstudy
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
class SecondActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
setContentView(R.layout.activity_second)
val name = as?.getString("name")
var tv_content = findViewById<TextView>(R.id.tv_content)
= name
}
}
<?xml version="1.0" encoding="utf-8"?>
&straintlayout.widget.ConstraintLayout xmlns:android="schemas.android/apk/res/android" xmlns:app="schemas.android/apk/res-auto"
xmlns:tools="schemas.android/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SecondActivity">
<TextView
android:id="@+id/tv_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Second Activity"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
/>
</straintlayout.widget.ConstraintLayout>
3.Activity之间传参
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论