728x90
1. New Project 생성 합니다.
2. activity_main.xml
<Button 만들기>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button1" />
</androidx.constraintlayout.widget.ConstraintLayout>
3. Empty Activity 만들기
<Button Activity 2개 생성 합니다.>
4. MainActivity.kt 수정 하기
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
button1.setOnClickListener {
val intent = Intent(this@MainActivity, MainActivity2::class.java)
startActivity(intent)
}
button2.setOnClickListener {
val intent = Intent(this@MainActivity, MainActivity3::class.java)
startActivity(intent)
}
}
}
5. activity_button1/2.xml
<TextView 만들기>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".MainActivity2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Activity1"
android:textSize="100dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
6. 시뮬레이터로 Activity 간 화면 전환 확인
728x90
'개발공부 > andorid' 카테고리의 다른 글
android#코틀린(Kotlin) 계산기 만들기 (2) | 2020.11.14 |
---|---|
android#Log.d 사용 하기 (0) | 2020.11.13 |
findViewById() 없이 XML 참조 하기 (0) | 2020.11.10 |
WebView 사용하기(Kotlin) (0) | 2020.11.03 |
android#로또 번호 뽑기(Kotlin) (3) | 2020.10.11 |