A, 활동. 안드로이드 스튜디오가 자동으로 우리를 위해 MainActivity를 작성합니다.
된 setContentView (R.layout.activity_main는) MainActivity 우리의 레이아웃 파일을 설정
패키지 com.example.helloworld; 수입 androidx.appcompat.app.AppCompatActivity; 수입 android.os.Bundle; 공공 클래스 MainActivity는 확장 AppCompatActivity { @Override가 보호 무효 에서 onCreate (번들 savedInstanceState) { 슈퍼 .onCreate (savedInstanceState를); 된 setContentView (R.layout.activity_main); } }
두 레이아웃. 기본적으로 여기에 ConstraintLayout (제약 레이아웃)를 사용한다. 그리고 디스플레이 안녕하세요을 추가! 텍스트 텍스트 뷰
<? XML 버젼 = "1.0"인코딩 = "UTF-8" ?> < androidx.constraintlayout.widget.ConstraintLayout 의 xmlns : 로이드 = "http://schemas.android.com/apk/res/android" 의 xmlns : 앱 = "HTTP "//schemas.android.com/apk/res-auto : 도구의 xmlns http://schemas.android.com/tools"= " 안드로이드 : layout_width ="match_parent " 안드로이드 : layout_height ="match_parent " 도구 : 문맥 = ".MainActivity" > < 텍스트 뷰의 로이드 : layout_width = "wrap_content" 로이드 : layout_height = "wrap_content" 응용 프로그램 : layout_constraintBottom_toBottomOf = "부모" 응용 프로그램 : layout_constraintLeft_toLeftOf = "부모" 응용 프로그램 : layout_constraintRight_toRightOf = "부모" 응용 프로그램 : layout_constraintTop_toTopOf = "부모" /> </ androidx.constraintlayout.widget.ConstraintLayout >
세, AndroidManifest.xml을. MainActivity이 파일에 등록
활동이 코드는 두 가지 주요 활동을 위해 다음과 같이 제공됩니다. 활동 항목이 응용 프로그램을 시작
< 액션 안드로이드 : 이름 = "android.intent.action.MAIN" />
< 카테고리 로이드 이름 = "android.intent.category.LAUNCHER" />
<? XML 버젼 = "1.0"인코딩 = "UTF-8" ?> < 매니페스트 의 xmlns : 로이드 = "http://schemas.android.com/apk/res/android" 패키지 = "com.example.helloworld" > < 응용 안드로이드 : allowBackup = "true"로 안드로이드 : 아이콘 = "@ 밉맵 / ic_launcher" 안드로이드 : 라벨 = "@ 문자열 / APP_NAME" 안드로이드 : roundIcon = "@ 밉맵 / ic_launcher_round" 안드로이드 : supportsRtl = "true"로 안드로이드 : 테마 = "@ 스타일 / AppTheme " > < 의도 필터 > < 활동 로이드 이름 = "android.intent.action.MAIN" /> < 카테고리 로이드 이름 = "android.intent.category.LAUNCHER" /> </ 텐트 필터 > </ 활동 > </ 애플리케이션 > </ 매니페스트 >