2021.01.19 - [안드로이드] - [안드로이드] DrawerLayout Navigaion 쉽게 만들어보기
[안드로이드] DrawerLayout Navigaion 쉽게 만들어보기
2021/01/15 - [안드로이드] - [안드로이드] TextToSpeech 텍스트(Text)를 음성으로 전환시켜주는 방법 2021/01/16 - [안드로이드] - [안드로이드]RecognizerIntent 음성을 텍스트(Text)로 전환시켜주는 방법 2021/..
aries574.tistory.com
2021.01.19 - [안드로이드] - [안드로이드] DrawerLayout Navigation 메뉴(Menu) 추가하기
[안드로이드] DrawerLayout Navigation 메뉴(Menu) 추가하기
2021/01/16 - [안드로이드] - [안드로이드]RecognizerIntent 음성을 텍스트(Text)로 전환시켜주는 방법 2021/01/17 - [안드로이드] - [안드로이드] 액티비티(Activity) 활동주기(Life Cycle) 2021/01/18 - [안드로..
aries574.tistory.com
2021.01.20 - [안드로이드] - [안드로이드] DrawerLayout Navigation Header 추가하기
[안드로이드] DrawerLayout Navigation Header 추가하기
2021/01/17 - [안드로이드] - [안드로이드] 액티비티(Activity) 활동주기(Life Cycle) 2021/01/18 - [안드로이드] - [안드로이드] OnClickListener onClick 하나로 다중 버튼 이벤트 설정하기 2021/01/19 - [안드..
aries574.tistory.com
이번 시간에는 Strings.xml에 등록된 문자를 자바(코드)에서 호출하는 방법을
알아보겠습니다.
화면 중앙에는 텍스트뷰를 만들고, 아래에는 버튼을 하나 만든 후에
버튼을 누르면 strings.xml에 있는 문자가 텍스트뷰에 보여지는 간단한 예제입니다.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".MainActivity">
<TextView
android:id="@+id/text_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textSize="60sp"
android:text="문자"/>
<Button
android:id="@+id/btn_change"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/text_name"
android:layout_centerHorizontal="true"
android:text="문자변경"
/>
</RelativeLayout>
R.strings.name
res 폴더에 strings파일의 name이 name인 것을 갖고온다는 의미입니다.
public class MainActivity extends AppCompatActivity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.text_name);
Button btn_chagne = findViewById(R.id.btn_change);
btn_chagne.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//strings.xml에 있는 name 이라는 문자를 호출
textView.setText(R.string.name);
}
});
}
}


2021.01.19 - [안드로이드] - [안드로이드] DrawerLayout Navigaion 쉽게 만들어보기
[안드로이드] DrawerLayout Navigaion 쉽게 만들어보기
2021/01/15 - [안드로이드] - [안드로이드] TextToSpeech 텍스트(Text)를 음성으로 전환시켜주는 방법 2021/01/16 - [안드로이드] - [안드로이드]RecognizerIntent 음성을 텍스트(Text)로 전환시켜주는 방법 2021/..
aries574.tistory.com
2021.01.19 - [안드로이드] - [안드로이드] DrawerLayout Navigation 메뉴(Menu) 추가하기
[안드로이드] DrawerLayout Navigation 메뉴(Menu) 추가하기
2021/01/16 - [안드로이드] - [안드로이드]RecognizerIntent 음성을 텍스트(Text)로 전환시켜주는 방법 2021/01/17 - [안드로이드] - [안드로이드] 액티비티(Activity) 활동주기(Life Cycle) 2021/01/18 - [안드로..
aries574.tistory.com
2021.01.20 - [안드로이드] - [안드로이드] DrawerLayout Navigation Header 추가하기
[안드로이드] DrawerLayout Navigation Header 추가하기
2021/01/17 - [안드로이드] - [안드로이드] 액티비티(Activity) 활동주기(Life Cycle) 2021/01/18 - [안드로이드] - [안드로이드] OnClickListener onClick 하나로 다중 버튼 이벤트 설정하기 2021/01/19 - [안드..
aries574.tistory.com
맘에 드셨다면 공감부탁드려요문의 댓글 환영합니다. |
| [안드로이드]정해진 시간에 알람 울리는 방법 Notification TimePicker (16) | 2021.06.28 |
|---|---|
| [안드로이드]업비트 api(Java)를 사용해서 자산 리스트 조회 (0) | 2021.06.20 |
| [안드로이드]업비트 api 사용해서 호가정보 가져오기 (0) | 2021.06.01 |
| [안드로이드]업비트 api 사용해서 해당 코인 체결내역 가져오기 (0) | 2021.05.31 |
| [안드로이드]업비트 api를 사용해서 현재가 정보 가져오기 (2) | 2021.05.28 |
댓글 영역