티스토리 뷰
@JvmOverloads + FrameLayout
back_title_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp">
<ImageButton
android:id="@+id/btnBack"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
android:background="@drawable/arrow_back"
android:foreground="?android:attr/selectableItemBackground" />
<TextView
android:id="@+id/tvTitle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:text=""
android:textColor="@android:color/black"
android:textSize="20sp"
android:textStyle="bold" />
</FrameLayout>
BackTitleLayout.kt
package com.jwsoft.kotlinproject
import android.app.Activity
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import android.widget.ImageButton
open class BackTitleLayout @JvmOverloads constructor(context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
defStyleRes: Int = 0)
: FrameLayout(context, attrs, defStyleAttr, defStyleRes) {
init {
LayoutInflater.from(context)
.inflate(R.layout.back_title_layout, this, true)
findViewById<ImageButton>(R.id.btnBack).setOnClickListener {
(context as Activity).finish()
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="center"
tools:context=".MainActivity">
<com.jwsoft.kotlinproject.BackTitleLayout
android:layout_width="match_parent"
android:layout_height="50dp" />
<TextView
android:id="@+id/tvPage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_gravity="center"
android:text="Main Activity"
android:textSize="30dp"
android:textStyle="bold|italic"
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"/>
</LinearLayout>
MainActivity.kt
package com.jwsoft.kotlinproject
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
tvPage.setOnClickListener {
startActivity(Intent(this, SecondActivity::class.java))
}
}
}
activity_second.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="center"
tools:context=".SecondActivity">
<com.jwsoft.kotlinproject.BackTitleLayout
android:layout_width="match_parent"
android:layout_height="50dp" />
<TextView
android:id="@+id/tvPage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_gravity="center"
android:text="Second Activity"
android:textSize="30dp"
android:textStyle="bold|italic"
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"/>
</LinearLayout>
SecondActivity.kt
package com.jwsoft.kotlinproject
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_second.*
class SecondActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_second)
tvPage.setOnClickListener {
startActivity(Intent(this, ThirdActivity::class.java))
}
}
}
activity_third.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="center"
tools:context=".ThirdActivity">
<com.jwsoft.kotlinproject.BackTitleLayout
android:layout_width="match_parent"
android:layout_height="50dp" />
<TextView
android:id="@+id/tvPage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_gravity="center"
android:text="Third Activity"
android:textSize="30dp"
android:textStyle="bold|italic"
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"/>
</LinearLayout>
ThirdActivity.kt
package com.jwsoft.kotlinproject
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_main.tvPage
class ThirdActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_third)
tvPage.setOnClickListener {
Toast.makeText(applicationContext, "마지막 페이지 입니다.", Toast.LENGTH_SHORT).show()
}
}
}
'Android > Kotlin' 카테고리의 다른 글
[Kotlin] VideoView (0) | 2020.08.15 |
---|---|
[Kotlin] SeekBar (0) | 2020.08.15 |
[Kotlin] StickyHeader + RecyclerView (0) | 2020.08.14 |
[Kotlin] @JvmOverloads (0) | 2020.08.12 |
[Kotlin] Glide (0) | 2020.08.10 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- TabLayout
- Intent
- ArrayList
- Design Pattern
- 코틀린
- DataBinding
- Android
- JSONArray
- 혀가 길지 않은 개발자
- 안드로이드 #코틀린 #Android #Kotlin
- fragment
- 안드로이드
- MVVM
- Livedata
- JSONObject
- java
- ViewPager2
- Kotlin
- coroutine
- CoordinatorLayout
- 자바
- View
- handler
- recyclerview
- ViewModel
- activity
- Architecture Pattern
- James Kim
- XML
- Vue.js #Vue.js + javascript
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
글 보관함