안드로이드 프로그래밍[Kotiln Code]/안드로이드 초기 강좌

[안드로이드] 텍스트뷰, 에디트텍스트 ( textView, EditText )

훈츠 2020. 4. 14. 18:34
반응형

안녕하세요. 훈츠 입니다. 텍스트뷰 와 에디트텍스트 사용하는 방법에 대해 포스팅합니다. 


'CharSequence' 는

String 계열의 클래스들이 상속받는 인터페이스 입니다.

'String , String Builder, String Buffer, Editable 등을 넣을 수 있습니다.

텍스트 뷰 (TextView)

문자열을 보여주는 텍스트 뷰 UI Component 입니다.

 

코드를 통한 Text Size 조정 하는법

  • TextView.setTextSize(10f) = sp 단위 

  • TextView.setTextSize( TypedValue.COMPLEX_UNIT_DIP.10f ) = dp 단위 


에디트 텍스트뷰 (EditTextView)

문자열을 보여주는 텍스트 뷰 UI Component 입니다.

 

inputType 의 값 

  • text : 모든 글자를 다 입력 가능 

  • textPassword : 패스워드 스크리닝 기능 

  • number : 숫자만 입력 가능

TextWatcher

 

실시간으로 텍스트를 받아 처리 할수 있습니다. 아래 예시처럼, TextWatcher 를 익명함수로 구현 한후, afterTextChanged와 beforeTextChanged, onTextChanged 를 이용하여 구현 할수 있습니다. 

1
2
3
4
5
6
7
8
9
10
11
//훈스 블로그---------------------------------------------------------------------------------------------------코드//
editText.addTextChangedListener(object:TextWatcher{
            override fun afterTextChanged(s: Editable?) {
            }
 
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
            }
            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
                previewText.text = s.toString()
            }
        })
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

 

반응형