일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 자바 예외
- 웹 브라우저 전쟁
- 데이터베이스
- 우아한테크
- 배열 예제
- HTML역사
- 크롤링 오류
- DoitSQL입문
- 자바
- 배열 3요소
- Doit입문SQL
- 예외
- 생성자
- 키-값 데이터베이스
- 웹브라우저 수용도
- 숫자형식오류
- R1C3
- SQL
- 자바 오류
- 함수
- 크롤링
- 페이지분석
- DoitSQL
- html
- SQL입문
- DoIt
- 숫자 형식
- 함수 선언
- dbms
- 예제
Archives
- Today
- Total
반응형
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 자바 예외
- 웹 브라우저 전쟁
- 데이터베이스
- 우아한테크
- 배열 예제
- HTML역사
- 크롤링 오류
- DoitSQL입문
- 자바
- 배열 3요소
- Doit입문SQL
- 예외
- 생성자
- 키-값 데이터베이스
- 웹브라우저 수용도
- 숫자형식오류
- R1C3
- SQL
- 자바 오류
- 함수
- 크롤링
- 페이지분석
- DoitSQL
- html
- SQL입문
- DoIt
- 숫자 형식
- 함수 선언
- dbms
- 예제
Archives
- Today
- Total
프로그래밍
[Do it! 안드로이드 앱] 자바) 로그인 화면과 메뉴 화면 전환하기 본문
728x90
반응형
도전과제 07
실행화면
디자인
프로젝트 설명
대부분의 업무용 앱에서 필요한 로그인 화면과 메뉴 화면을 간단하게 만들고 두 화면 간을 전환하면서 토스트로 메세지를 띄워주도록 만들어 보세요
1. 로그인 화면과 메뉴 화면 각각을 액티비티로 만듭니다.
2. 로그인 화면에는 하나의 버튼이 들어가도록 합니다.
3. 메뉴 화면에는 세 개의 버튼이 들어가도록 하고 각각 '고객 관리', '매출 관리', '상품 관리'라는 이름으로 표시합니다.
4. 로그인 화면의 버튼을 누르면 메뉴 화면으로 이동합니다.
5. 메뉴 화면의 버튼 중에서 하나를 누르면 로그인 화면으로 돌아온 후 선택된 메뉴의 이름을 토스트 메세지로 보여줍니다.
activity_main.xml
<?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"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="로그인하기"
android:textSize="60dp"/>
<Button
android:id="@+id/BtnLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="200dp"
android:text="로그인"
android:textSize="30dp"/>
</LinearLayout>
activity_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MenuActivity"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="60dp"
android:text="메인메뉴" />
<Button
android:id="@+id/Btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="100dp"
android:textSize="30dp"
android:text="고객 관리"/>
<Button
android:id="@+id/Btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:textSize="30dp"
android:text="매출 관리"/>
<Button
android:id="@+id/Btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="30dp"
android:text="상품 관리"/>
</LinearLayout>
MainActivity.java
package com.sample.doitmission_07;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button btnLogin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnLogin = findViewById(R.id.BtnLogin);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, MenuActivity.class);
startActivity(intent);
}
});
}
}
MenuActivity.java
package com.sample.doitmission_07;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MenuActivity extends AppCompatActivity {
Button btn1, btn2, btn3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
btn1 = findViewById(R.id.Btn1);
btn2 = findViewById(R.id.Btn2);
btn3 = findViewById(R.id.Btn3);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "고객 관리", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MenuActivity.this, MainActivity.class);
startActivity(intent);
}
});
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "매출 관리", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MenuActivity.this, MainActivity.class);
startActivity(intent);
}
});
btn3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "상품 관리", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MenuActivity.this, MainActivity.class);
startActivity(intent);
}
});
}
}
추후에 만든 액티비티를 인식 못할 경우 Manifest에 추가해준다
Manifest.xml
<activity android:name=".MenuActivity"/>
728x90
반응형
'안드로이드 > Do it! 안드로이드 앱프로그래밍' 카테고리의 다른 글
[Do it! 안드로이드 앱] 자바) 버튼으로 프래그먼트 교체하기 (0) | 2022.05.23 |
---|---|
[Do it! 안드로이드 앱] 자바) 세 개 이상의 화면 만들어 전환하기 (0) | 2022.05.23 |
[Do it! 안드로이드 앱] 자바) 두 종류의 버튼 모양 만들기 (0) | 2022.05.18 |
[Do it! 안드로이드 앱] 자바) SMS 입력 화면 만들고 글자의 수 표시하기 (0) | 2022.05.16 |
[Do it! 안드로이드 앱] 자바) 두 개의 이미지뷰에 이미지 번갈아 보여주기 (0) | 2022.05.16 |
Comments