일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 안드로이드
- WebView
- Android WebView
- 카카오 알고리즘
- 습관만들기
- 프로그래머스 알고리즘
- Android DataBinding
- Kotlin FCM
- Kotlin
- 알고리즘 자바
- Android 12 대응
- Android Navigation
- Java
- MVP Architecture
- OkHttp Interceptor
- Android ProgressBar
- 66챌린지
- android recyclerview
- 안드로이드 fcm
- Android
- 안드로이드 갤러리 접근
- Android Jetpack
- 안드로이드 카카오 로그인
- 영어공부
- scope function
- DataBinding
- Android Interceptor
- Android ViewPager2
- Android 12
- 영어독립365
Archives
- Today
- Total
Developer Geek
안드로이드 문자열 리소스(strings.xml) 사용 예제 본문
반응형
문자열 리소스(strings.xml) - /res/values/strings.xml
안드로이드 프로젝트에서 /res/value 경로 아래에 strings.xml이라는 문자열 리소스 파일이 있다.
사용할 문자열 추가하기
프로젝트를 처음 생성하면 아래와 같이 기본으로 app_name이라는 이름을 가진 문자열 리소스가 있다. app_name과 같은 형태로
<resources>
<string name="app_name">DataBindingBasics</string>
<string name="name">devGeek</string>
<string name="what_is_your_nickname">What is your nickname?</string>
</resources>
소스에서 문자열 리소스 사용하기 - activity_main.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"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingHorizontal="20dp"
tools:context=".MainActivity">
<TextView
android:id="@+id/name_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/name"
android:textAlignment="center"
android:textColor="@color/black"
android:textSize="20sp" />
<EditText
android:id="@+id/editText_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/what_is_your_nickname"
android:textAlignment="center"
android:textColor="@color/black"
android:textSize="20sp" />
</LinearLayout>
<TextView> 태그의 속성 중 android:text=""에 <string> 태그의 name 속성 값을 넣어준다.
ex). android:text="@string/name"
ex). android:text="@string/what_is_your_nickname
결과 화면
반응형
'안드로이드' 카테고리의 다른 글
Android 키보드 생성 시, Bottom Navigation Hide (0) | 2021.10.28 |
---|---|
안드로이드 style.xml 사용 예제 (0) | 2021.10.19 |
안드로이드 카카오 SDK V2 로그인 - part2(코드) (0) | 2021.09.27 |
안드로이드 카카오 SDK V2 로그인 - part1(프로젝트 셋업) (0) | 2021.09.27 |
Android(Kotlin) RecyclerView Example (0) | 2021.09.08 |
Comments