Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
Tags
- hongdroid
- 개발강의
- 플러터
- Android Studio
- flutter
- 안드로이드 네비게이션 메뉴
- Android
- IOS
- 코딩
- 안드로이드 예제
- 안드로이드 기초
- 앱 만들기
- android tutorial
- java
- 자바 튜토리얼
- 개발자
- 앱 만드는 법
- 안드로이드 코딩 기초
- 홍드로이드
- android studio 앱 만드는 법
- 홍드로이드 강의
- Android Java
- android example
- 안드로이드 튜토리얼
- 안드로이드 앱 만들기
- 안드로이드 서비스
- 안드로이드 스튜디오
- 코틀린
- 안드로이드
- 자바
Archives
- Today
- Total
홍드로이드의 야매코딩
#25 안드로이드 스튜디오 SNS 앱 만들기 1 (인스타그램 하단바) [ 홍드로이드 ] 본문
< activity_main.xml >
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 29 30 | <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.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" tools:context=".MainActivity"> <android.support.design.widget.BottomNavigationView android:id="@+id/bottomNavi" android:layout_width="match_parent" android:layout_height="wrap_content" app:itemIconTint="#000000" app:itemTextColor="#000000" app:layout_constraintBottom_toBottomOf="parent" app:menu="@menu/bottom_menu" tools:layout_editor_absoluteX="8dp" /> <FrameLayout android:id="@+id/main_frame" android:layout_width="match_parent" android:layout_height="659dp" app:layout_constraintBottom_toTopOf="@+id/bottomNavi" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> </FrameLayout> </android.support.constraint.ConstraintLayout> | cs |
< frag1.xml >
1 2 3 4 5 6 7 8 9 10 11 12 13 | <?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" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1번화면 입니다." android:textSize="40sp"/> </LinearLayout> | cs |
< frag2.xml >
1 2 3 4 5 6 7 8 9 10 11 12 13 | <?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" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="2번화면 입니다." android:textSize="40sp"/> </LinearLayout> | cs |
< frag3.xml >
1 2 3 4 5 6 7 8 9 10 11 12 13 | <?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" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="3번화면 입니다." android:textSize="40sp"/> </LinearLayout> | cs |
< frag4.xml >
1 2 3 4 5 6 7 8 9 10 11 12 13 | <?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" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="4번화면 입니다." android:textSize="40sp"/> </LinearLayout> | cs |
< frag5.xml >
1 2 3 4 5 6 7 8 9 10 11 12 13 | <?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" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="5번화면 입니다." android:textSize="40sp"/> </LinearLayout> | cs |
< MainActivity.java >
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | package com.example.bottomnavi; import android.support.annotation.NonNull; import android.support.design.widget.BottomNavigationView; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.MenuItem; public class MainActivity extends AppCompatActivity { private BottomNavigationView bottomNavigationView; // 바텀 네비게이션 뷰 private FragmentManager fm; private FragmentTransaction ft; private Frag1 frag1; private Frag2 frag2; private Frag3 frag3; private Frag4 frag4; private Frag5 frag5; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); bottomNavigationView = findViewById(R.id.bottomNavi); bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.action_airplane: setFrag(0); break; case R.id.action_airport: setFrag(1); break; case R.id.action_bt: setFrag(2); break; case R.id.action_call: setFrag(3); break; case R.id.action_run: setFrag(4); break; } return true; } }); frag1 = new Frag1(); frag2 = new Frag2(); frag3 = new Frag3(); frag4 = new Frag4(); frag5 = new Frag5(); setFrag(0); // 첫 프래그먼트 화면을 무엇으로 지정해줄 것인지 선택. } // 프래그먼트 교체가 일어나는 실행문이다. private void setFrag(int n) { fm = getSupportFragmentManager(); ft = fm.beginTransaction(); switch (n) { case 0: ft.replace(R.id.main_frame, frag1); ft.commit(); break; case 1: ft.replace(R.id.main_frame, frag2); ft.commit(); break; case 2: ft.replace(R.id.main_frame, frag3); ft.commit(); break; case 3: ft.replace(R.id.main_frame, frag4); ft.commit(); break; case 4: ft.replace(R.id.main_frame, frag5); ft.commit(); break; } } } | cs |
< Frag1.java >
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 | package com.example.bottomnavi; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class Frag1 extends Fragment { private View view; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(R.layout.frag1, container, false); return view; } } | cs |
< Frag2.java >
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 | package com.example.bottomnavi; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class Frag2 extends Fragment { private View view; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(R.layout.frag2, container, false); return view; } } | cs |
< Frag3.java >
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 | package com.example.bottomnavi; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class Frag3 extends Fragment { private View view; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(R.layout.frag3, container, false); return view; } } | cs |
< Frag4.java >
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 | package com.example.bottomnavi; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class Frag4 extends Fragment { private View view; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(R.layout.frag4, container, false); return view; } } | cs |
< Frag5.java >
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 | package com.example.bottomnavi; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class Frag5 extends Fragment { private View view; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(R.layout.frag5, container, false); return view; } } | cs |
'Android Java' 카테고리의 다른 글
#27 안드로이드 스튜디오 버튼 클릭 효과 만들기 (Button Selector) 예제 [ 홍드로이드 ] (2) | 2019.06.08 |
---|---|
#26 안드로이드 스튜디오 다음 화면으로부터 값 전달받기 (StartActivityForResult) 예제 [ 홍드로이드 ] (0) | 2019.06.08 |
#24 안드로이드 스튜디오 구글맵 (Google Map) 예제 [ 홍드로이드 ] (0) | 2019.06.08 |
#23 안드로이드 스튜디오 뒤로가기 두번눌러 앱 종료 (android onBackPressed) 예제 [ 홍드로이드 ] (0) | 2019.06.08 |
#22 안드로이드 스튜디오 음악 재생 MP3 (서비스) 예제 [ 홍드로이드 ] (1) | 2019.06.08 |
Comments