Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- git 충돌
- 회사 네트워크
- 코닥 미니샷2
- Git 기초
- xml화면 검은색
- 약과팅
- 카카오맵 api
- KakaoMap API
- 장인약과
- 전기신호
- FCS
- 가정 네트워크
- android xml 오류
- 약과팅 경험!
- 안드로이드 xml 화면 오류
- network
- 성공했으면 꿀팁! 이런거라도 적는데 그게 아니니 뭐 적을게 없네요
- 장인한과
- kakaomap
- 역캡슐화
- 네트워크 기초
- android xml 화면 검은색
- OSI 모델
- TCP/IP 모델
- clone vs pull
- 모두의 네트워크
- git #
- Android
- git
- xml 화면
Archives
- Today
- Total
괴발개발
[Android] About ViewBinding 본문
ViewBinding에 대해서 알아본다.
1. build.gradle(module) 에 해당 코드를 추가한다.
(난 안드로이드 버전 4..0 이상이라 이렇게 썼다.
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
buildFeatures { viewBinding = true }
4.0보다 안된다면 android { }안에
viewBinding
{enabled = true}
를 넣어야한다.
2. xml을 작성한다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
tools:context=".MainActivity"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:textColor="#FF333333"
android:text="Hello"
tools:ignore="MissingConstraints" />
</LinearLayout>
3. 이렇게 하고 MainActivity.java에 가면
ActivityMainBinding이 저절로 생성된다.
MainActivity.java 코드는 이와 같다.
package com.example.fragment;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.example.fragment.databinding.ActivityMainBinding;
public class MainActivity extends AppCompatActivity {
ActivityMainBinding mainBinding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mainBinding= ActivityMainBinding.inflate(getLayoutInflater());
setContentView(mainBinding.getRoot());
mainBinding.tv.setText("asd");
}
}
'Study > Android Studio' 카테고리의 다른 글
| [Android] About DataBinding (0) | 2022.04.14 |
|---|---|
| [ToolBar] 툴바는 항상 헷갈려 (1) (0) | 2022.03.23 |
| [android Studio] noactionbar 설정 후, 다크모드로 적용될때 (0) | 2022.01.14 |