티스토리 뷰
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.javaproject.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.java
package com.jwsoft.javaproject;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import com.jwsoft.javaproject.databinding.ActivityMainBinding;
public class MainActivity extends AppCompatActivity {
public ActivityMainBinding binding;
public String str = "혀가 길지 않은 개발자";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
binding.setMainActivity(this);
binding.setLifecycleOwner(this);
binding.btnRed.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
binding.txtView.setTextColor(Color.parseColor("#FFBBBB"));
binding.invalidateAll();
}
});
binding.btnGreen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
binding.txtView.setTextColor(Color.parseColor("#BBFFBB"));
binding.invalidateAll();
}
});
}
}
'Android > Java' 카테고리의 다른 글
[Java] DataBinding + LiveData (0) | 2020.07.09 |
---|---|
[Java] LiveData (0) | 2020.07.09 |
[Java] ViewPager2 + RecyclerView.Adapter (0) | 2020.07.04 |
[Java] ViewPager2 + FragmentStateAdapter (0) | 2020.07.04 |
[Java] CoordinatorLayout + AppBarLayout + Toolbar + RecyclerView (0) | 2020.07.03 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- JSONArray
- Android
- DataBinding
- XML
- James Kim
- 혀가 길지 않은 개발자
- CoordinatorLayout
- Design Pattern
- Livedata
- View
- Architecture Pattern
- TabLayout
- activity
- MVVM
- 안드로이드 #코틀린 #Android #Kotlin
- fragment
- ArrayList
- JSONObject
- Vue.js #Vue.js + javascript
- 코틀린
- coroutine
- 자바
- ViewModel
- recyclerview
- Kotlin
- 안드로이드
- ViewPager2
- handler
- Intent
- java
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함