[Git, GitHub]
1. Git 설치하기
1) Git 홈페이지에서 실행파일 다운받기
: https://www.git-scm.com > Downloads 클릭 > (자신이 사용하고 있는 운영체제 클릭하면 됨) Windows 클릭
> git 실행파일 다운로드..!!
2) 다운받은 Setup 실행파일 실행
: 아래의 사진과 같이 선택 후 모두 Next 클릭 라이센스 확인 후 Next > 다운받을 폴더 확인 후 Next
> 아래의 그림과 같이 세팅 후 Next
> 아래의 사진과 같이 선택 후 Next 클릭
> 아래의 사진과 같이 선택 후 Next 클릭
> Enable Git Credential Manager 체크 해제(선택사항, 학원컴에서는 체크 해제하기로 함)
> Next 클릭 > 다운로드 완..!!
2. GitHub 저장(push : 원격저장소에 올리기)
1) 제대로 Git을 다운 받았다면 Path to Git executable에 다운받은 파일 경로를 확인할 수 있다
2) 안드로이드 스튜디오에 GitHub 계정 등록하기
: File > Settings ... 클릭 > Settings 창이 뜸 > Version Control > GitHub 클릭
> 계정 등록할 수 있는 곳으로 들어 갈 수 있음 > Add 플러스 그림 클릭하면 그럼 로그인 팝업 창이 뜸 > 로그인하기
> 아래의 그림과 같이 확인되면 계정 등록이 된것임
[추가] git에 올리고 싶지 않은 것들은 .gitignore에 기입하면 됨
3) push(원격 저장소에 올리는 것)하기
[위의 commit 실패, 왜?] git config을 실행 안해서
[commit을 하기 위해서는 뭘 해야할까?] 커맨드창 열고 아래의 명령어 입력
git config --global user.name “이름”
git config --global user.email “이메일”
[cmd 창에 위의 명령어를 입력 후 다시 시도 > 정상적으로 commit 및 push됨] Commit and Push 클릭
> Commit and Push 클릭
> 아래와 같은 팝업창이 뜨면서 소스가 GitHub에 올라감
> Description에서 설정한 이름이 '안드로이드 수업'이라고 기재된 제목으로 노출됨
('첫 커밋, 2020-04-13'으로 설정했던 이름은 Edit를 통해 '안드로이드 수업'으로 변경함)
[추가] 아래의 git 폴더는 로컬 저장소
3. GitHub 불러오기(clone : 원격저장소를 내 컴퓨터에 받아오기, clone은 단 한 번만..!!)
: Check out project from Version Control > git 클릭
> Clone of download 클릭하면 URL을 복사 할 수 있음
> 다운 받은 URL을 입력 후 기존 프로젝트 명과 동일하게 작성 설정
> Test 클릭 > Connection successful 메시지가 확인되면 Clone 클릭
> 아래의 팝업창이 뜨면 Yes 클릭하면 정상적으로 clone 되어 GitHub에 저장된 내용 불러올 수 있음...!!
[안드로이드]
1. Constraint Layout(제약 레이아웃)
: 현재 기본 레이아웃(과거에는 RelativeLayout이 기본 레이아웃이였으나 바뀜)
2. Event(이벤트)
: 뷰(View)에는 다양한 동작이 발생하거나, 혹은 상태 변화가 발생될 수 있는데 이러한 것들을 이벤트라고 한다.
3. Listener(리스너)
: 안드로이드 프로그래밍은 각각의 '뷰'에 해당 '이벤트'에 대해 이벤트 발생할때 동작하는
'이벤트 리스너'를 장착하여 프로그래밍을 한다.
예) '버튼 뷰'에 '클릭 이벤트'가 발생시 동작하는 'OnClickListener'를 작성하여 장착..!!
장착하는 메소드는 'setOnClickListener'
4. 모듈 제거
1) 프로젝트에서 모듈 제거
2) Run/Debug Configuration 에서도 모듈 제거
3) 디스크에서도 모듈 제거
5. 모듈 이름 변경
1) Shift + F6 으로 이름 변경
2) Run/Debug Configuration 이름 변경
3) res > values > string.xml 클릭 > app_name 에 원하는 이름으로 변경
6. a002_layout 모듈
1) constraint1 레이아웃
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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">
<Button
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="68dp"
android:layout_marginTop="128dp"
android:text="Button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="132dp"
android:layout_marginTop="188dp"
android:text="Button"
app:layout_constraintStart_toEndOf="@+id/button7"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button9"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
2) constraint2 레이아웃
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="40dp" />
<Button
android:id="@+id/button10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Button"
app:layout_constraintStart_toStartOf="@+id/guideline"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Button"
app:layout_constraintStart_toStartOf="@+id/guideline"
app:layout_constraintTop_toBottomOf="@+id/button10" />
<Button
android:id="@+id/button12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Button"
app:layout_constraintStart_toStartOf="@+id/guideline"
app:layout_constraintTop_toBottomOf="@+id/button11" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_end="46dp" />
<Button
android:id="@+id/button13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintStart_toStartOf="@+id/guideline" />
<Button
android:id="@+id/button14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintStart_toEndOf="@+id/button13" />
<Button
android:id="@+id/button16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintStart_toEndOf="@+id/button14" />
</androidx.constraintlayout.widget.ConstraintLayout>
3) constraint3 레이아웃
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_end="26dp" />
<Button
android:id="@+id/button15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="28dp"
android:layout_marginBottom="28dp"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/guideline4"
app:layout_constraintEnd_toStartOf="@+id/guideline3" />
<Button
android:id="@+id/button18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="28dp"
android:layout_marginBottom="28dp"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/guideline4"
app:layout_constraintStart_toStartOf="@+id/guideline3" />
</androidx.constraintlayout.widget.ConstraintLayout>
4) constraint4 레이아웃
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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">
<Button
android:id="@+id/button5"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button10"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/button9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button5" />
<Button
android:id="@+id/button9"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginBottom="8dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
[추가] constraint 레이아웃에서 LinearLayout 레이아웃으로 변경하기
[추가] LinearLayout 레이아웃 horizontal에서 vertical로 변경하기
7. a003_listener 모듈
1) MainActivity 액티비티, activity_main 레이아웃
<?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"
tools:context=".MainActivity"
android:id="@+id/ll">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="changeText"
android:text="Button1" />
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button2" />
<Button
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button3" />
</LinearLayout>
<TextView
android:id="@+id/tvResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="결과창"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="*">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btnA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A"
android:layout_column="0"
android:tag="Apple"/>
<Button
android:id="@+id/btnB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B"
android:layout_column="1"
android:tag="Banana"/>
<Button
android:id="@+id/btnC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:text="C"
android:tag="Cookie"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btnD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="D"
android:layout_column="0"
android:tag="Donuts" />
<Button
android:id="@+id/btnE"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:text="E"
android:tag="Eclair" />
<Button
android:id="@+id/btnF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:text="F"
android:tag="Froyo" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/et"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:layout_span="3"
android:ems="10" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btnClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="2"
android:layout_column="1"
android:text="Clear" />
</TableRow>
</TableLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btnInc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+"
android:layout_weight="1" />
<Button
android:id="@+id/btnDec"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
package com.example.a003_listener;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
TextView tvResult;
EditText et;
// onCreate()
// 액티비티(화면 객체)가 생성될때 호출되는 메소드
// 액티비티 초기화 하는 코드 작성.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn1 = findViewById(R.id.btn1);
Button btn2 = findViewById(R.id.btn2);
Button btn3 = findViewById(R.id.btn3);
tvResult = findViewById(R.id.tvResult);
et = findViewById(R.id.et);
final LinearLayout ll = findViewById(R.id.ll); // Local inner 에서 사용할수 있는 것은
// 멤버변수, effective final !!
// 방법2 : 익명 클래스 (anonymous class) 사용.
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { // 클릭되었을때 호출되는 메소드 (콜백 메소드 callback method)
Log.d("myapp", "버튼2가 클릭 되었습니다");
tvResult.setText("버튼2 가 클릭됨");
tvResult.setBackgroundColor(Color.YELLOW);
}
});
// 다양한 이벤트, 다양한 리스너 등록 가능
// 모바일에서는 더블 클릭을 할 수 없음
btn2.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) { // 롱클릭 발생시 수행하는 콜백 메소드
Log.d("myapp", "버튼2가 롱클릭 되었습니다.");
tvResult.setText("버튼2가 롱클릭 되었습니다");
tvResult.setBackgroundColor(Color.CYAN);
//return false; // false 리턴하면 이벤트가 click 까지 간다.
return true; // true 리턴하면 이벤트가 long click 으로 소멸 (consume) 된다.
}
});
// 방법3 : lambda - expression 사용하기
// AndroidStudio 의 세팅 필요! ppt 참조!
btn3.setOnClickListener((v) -> { // onClick(View v)
Log.d("myapp", "버튼3 가 클릭 되었다");
tvResult.setText("버튼3 클릭됨");
ll.setBackgroundColor(Color.rgb(164, 198, 57));
});
// 방법4 : implement 한 클래스 사용
Button btnA = findViewById(R.id.btnA);
Button btnB = findViewById(R.id.btnB);
Button btnC = findViewById(R.id.btnC);
Button btnD = findViewById(R.id.btnD);
Button btnE = findViewById(R.id.btnE);
Button btnF = findViewById(R.id.btnF);
class MyListener implements View.OnClickListener{
String name;
public MyListener(String name) {this.name = name;}
@Override
public void onClick(View v) {
String tag = (String)v.getTag();
String text = (String)((Button)v).getText(); // getText() 는 CharSequence 객체 리턴
String msg = String.format("%s 버튼 %s 이 클릭[%s]", name, text, tag);
Log.d("myapp", msg);
tvResult.setText(msg);
et.setText(et.getText().append(name));
}
}
btnA.setOnClickListener(new MyListener("안녕1"));
btnB.setOnClickListener(new MyListener("안녕2"));
btnC.setOnClickListener(new MyListener("안녕3"));
btnD.setOnClickListener(new MyListener("안녕4"));
btnE.setOnClickListener(new MyListener("안녕5"));
btnF.setOnClickListener(new MyListener("안녕6"));
// 방법5 : 액티비티가 implement
Button btnClear = findViewById(R.id.btnClear);
btnClear.setOnClickListener(this);
// 연습
// +, - 버튼 누르면 tvResult 의 글씨가 점점 커지고/작아지게 하기
// getTextSize() : float 값 리턴
Button btnInc = findViewById(R.id.btnInc);
Button btnDec = findViewById(R.id.btnDec);
btnInc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
float size = tvResult.getTextSize();
Log.d("myapp", "글꼴사이즈: " + size);
tvResult.setTextSize(0, size + 5);
}
});
btnDec.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
float size = tvResult.getTextSize();
Log.d("myapp", "글꼴사이즈: " + size);
tvResult.setTextSize(0, size - 5);
}
});
} // end onCreate()
// 방법1 : 레이아웃 xml 의 onXXX 속성으로 지정
public void changeText(View v){
// Log.d(tag, message)
// Log 창의 Debug 메세지로 출력
Log.d("myapp", "버튼 1이 클릭되었습니다");
tvResult.setText("버튼1 이 클릭 되었습니다.");
}
// 방법5 : 액티비티가 implement 한 것을 사용
@Override
public void onClick(View v) {
Log.d("myapp", "Clear 버튼이 클릭되었습니다.");
tvResult.setText("Clear버튼이 클릭되었습니다");
et.setText("");
}
} // end Activity
** Log.d(tag, message) : Log 창의 Debug 메시지 출력
[방법1] 레이아웃 xml 의 속성으로 지정
[방법2] 익명 클래스 (anonymous class) 사용
** 안드로이드 스튜디오에서 자바는 기본 세팅이 1.7버전으로 설정되어 있다
람다는 1.8 버전부터 제공되므로 자바 설정을 1.8버전으로 변경하는 과정이 반드시 필요하다!!
[방법3] lambda - expression 사용하기
[방법4] implement 한 클래스 사용
[방법5] 액티비티가 implement
8. a004_widget 모듈
1) MainActivity 액티비티, activity_main 레이아웃
<?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"
tools:context=".MainActivity" >
<TextView
android:id="@+id/tvTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="EditText"
android:textAppearance="@style/TextAppearance.AppCompat.Display1" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="이름"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:id="@+id/etName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="15"
android:inputType="textPersonName"
android:text="Name" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tvPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="비밀번호"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:id="@+id/etPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tvEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="이메일"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:id="@+id/etEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress"
android:hint="이메일 입력"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tvNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="숫자"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:id="@+id/etNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tvResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_span="2"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
</TableRow>
</TableLayout>
</ScrollView>
</LinearLayout>
package com.example.a004_widger;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText etName, etPassword, etNumber, etEmail;
TextView tvName, tvPassword, tvNumber, tvEmail;
TextView tvResult;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etName = findViewById(R.id.etName);
etPassword = findViewById(R.id.etPassword);
etNumber = findViewById(R.id.etNumber);
etEmail = findViewById(R.id.etEmail);
tvName = findViewById(R.id.tvName);
tvPassword = findViewById(R.id.tvPassword);
tvNumber = findViewById(R.id.tvNumber);
tvEmail = findViewById(R.id.tvEmail);
tvResult = findViewById(R.id.tvResult);
// 포커스 변화
etName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
// hasFocus: true-포커스 받은 경우 false - 포커스 잃은 경우
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
((EditText)v).setBackgroundColor(Color.YELLOW);
} else {
// 투명색
((EditText)v).setBackgroundColor(Color.parseColor("#00000000"));
}
}
});
// 키보드가 눌릴때
// 자판 키보드에만 반응 !
etPassword.setOnKeyListener(new View.OnKeyListener() {
// keyCode : 눌린 키의 코드값
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
tvResult.setText( ((EditText)v).getText().toString() );
return false;
}
});
// 값의 변화 (입력 완료)
etEmail.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
tvResult.setText("입력완료:" + actionId);
return false;
}
});
} // end onCreate()
} // end Activity
'웹_프론트_백엔드 > JAVA프레임윅기반_풀스택' 카테고리의 다른 글
2020.04.17 (0) | 2020.04.17 |
---|---|
2020.04.16 (0) | 2020.04.16 |
2020.04.13 (0) | 2020.04.13 |
2020.04.10 (0) | 2020.04.10 |
2020.04.09 (0) | 2020.04.09 |