본문 바로가기
기초 Android

안드로이드 스튜디오 TextView로 글씨를 작성해보자.

by 일용직 코딩노동자 2020. 7. 24.
728x90
반응형

TextView라는 기능으로 안드로이드 스튜디오에서 글씨를 작성할수있습니다.

 

<?xml version="1.0" encoding="utf-8"?>
<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"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="안녕하세요."
        android:textColor="#000000"
        android:textSize="30dp"
        android:id="@+id/text1">
    </TextView>

</LinearLayout>

전체코드인데요.

 

오른쪽 위를 보시면 

 

Code Splite Design으로 나눠져있습니다.

 

스플릿 탭으로 나눠서 보시면 위 사진처럼 작성한 코드가 오른쪽에 실시간으로 표기됩니다.

 

그럼 이제 자바소스딴에서 이 Text를 변경해볼게요.

 

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    TextView text1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        text1 = findViewById(R.id.text1);

        text1.setText("안녕못한다..");

    }
}

 

이렇게 하시면되는데

 

맨위에 TextView text1; 를 선언해줍니다.

 

자료형을 배우셨다는 조건하에 한번 설명해볼게요.

 

int String long float double같은 정수형 문자형 실수형 등의 자료형을 배우셨을겁니다.

 

그럼 똑같이 TextView라는 자료형이 있다고 생각하시면됩니다.

 

변수의 타입은 TextView 변수의 이름은 text1입니다.

 

그럼 이제 아까 Xml 화면에서 지정해준  id값이 있습니다.

 

요 id값하고 연결을 해줘야~ 저희가 지정한 TextView를 수정이 가능합니다.

 

그 과정이 바로 text1 = findViewByID(R.id.text1); 입니다.

 

TextView라는 자료형으로 선언한 text1에다가 text1이라는 id값을 가지는 녀석을 가져와! 라는 뜻이에요..!

 

그리고 text1. 자 여기서 . 을 찍었는데 그렇단 애기는 text1이라는 녀석 안에 setText라는 녀석이 있다는거에요.

 

궁금하시다면 컨트롤키 누르고 text1을 한번 클릭해서 들어가보세용.!

 

setText기능은 텍스트를 바꾸는 기능이랍니다.

 

극 기초적인 포스팅을 위주로 한번 시작해보는 중입니다.

 

처음 안드로이드를 시작하시는 분들에게 도움이 되셨으면 좋겠습니다.

728x90
반응형

댓글