티스토리 뷰
build.gradle (Module: app)
android {
dataBinding {
enabled = true
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<layout>
<data>
<variable
name="mainActivity"
type="com.jwsoft.kotlinproject.MainActivity" />
</data>
<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:gravity="center"
tools:context=".MainActivity">
<TextView
android:id="@+id/txtView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{mainActivity.str}"
android:textSize="30dp"
android:textStyle="bold"
android:textAlignment="center"
android:hint="버튼 클릭 전" />
<Button
android:id="@+id/btnRed"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="Red"
android:textSize="20dp"
android:textAllCaps="false" />
<Button
android:id="@+id/btnGreen"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="Green"
android:textSize="20dp"
android:textAllCaps="false" />
</LinearLayout>
</layout>
MainActivity.kt
package com.jwsoft.kotlinproject
import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.databinding.DataBindingUtil
import com.jwsoft.kotlinproject.databinding.ActivityMainBinding
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
var str: String = "혀가 길지 않은 개발자"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
binding.mainActivity = this
binding.lifecycleOwner = this
binding.btnRed.setOnClickListener {
binding.txtView.setTextColor(Color.parseColor("#FFBBBB"))
binding.invalidateAll()
}
binding.btnGreen.setOnClickListener {
binding.txtView.setTextColor(Color.parseColor("#BBFFBB"))
binding.invalidateAll()
}
}
}
'Android > Kotlin' 카테고리의 다른 글
[Kotlin] DataBinding + LiveData (0) | 2020.07.09 |
---|---|
[Kotlin] LiveData (0) | 2020.07.09 |
[Kotlin] ViewPager2 + FragmentStateAdapter (0) | 2020.07.06 |
[Kotlin] CoordinatorLayout + AppBarLayout + Toolbar + RecyclerView (0) | 2020.07.04 |
[Kotlin] ViewPager2 + RecyclerView.Adapter (0) | 2020.07.03 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 안드로이드 #코틀린 #Android #Kotlin
- TabLayout
- CoordinatorLayout
- recyclerview
- 자바
- Vue.js #Vue.js + javascript
- Intent
- 코틀린
- James Kim
- Kotlin
- 안드로이드
- JSONObject
- JSONArray
- 혀가 길지 않은 개발자
- Design Pattern
- MVVM
- Architecture Pattern
- Livedata
- ArrayList
- View
- handler
- activity
- fragment
- XML
- Android
- ViewModel
- java
- DataBinding
- ViewPager2
- coroutine
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함