MainActivity.java
package com.example.hw4_20211319;
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 {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 상단바 이미지 추가
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.ic_launcher);
// 컴포넌트 매칭
// 페이지 전환 버튼1
Button button1 = (Button)findViewById(R.id.button1);
// 이벤트 정의
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// new Intent(현재 클래스, 이동할 클래스); 의미이다.
// startActivity 인텐트 이동 시작을 의미한다.
Intent intent = new Intent(getApplicationContext(), MainActivity2.class);
startActivity(intent);
}
});
}
}
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"
android:orientation="vertical"
android:background="@color/white"
tools:context=".MainActivity">
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/strbtn_next"
android:backgroundTint="@color/gray"
android:textColor="@color/black"/>
</LinearLayout>
MainActivity2.java
package com.example.hw4_20211319;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity2 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
// 상단바 이미지 추가
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.ic_launcher);
// 컴포넌트 매칭
// 페이지 전환 버튼
Button button2 = (Button)findViewById(R.id.button2);
Button button3 = (Button)findViewById(R.id.button3);
// 이벤트 발생
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), MainActivity3.class);
startActivity(intent);
}
});
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
});
}
}
activity_main2.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"
android:background="@color/green"
android:orientation="vertical"
tools:context=".MainActivity2">
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/strbtn_next"
android:backgroundTint="@color/green_b"
android:textColor="@color/black" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/strbtn_back"
android:backgroundTint="@color/green_b"
android:textColor="@color/black" />
</LinearLayout>
string.xml
<resources>
<string name="app_name1">연습문제 10-5</string>
<string name="app_name2">second 액티비티</string>
<string name="app_name3">Third 액티비티</string>
<string name="strbtn_next">새화면 열기</string>
<string name="strbtn_back">돌아가기</string>
</resources>
color.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="black_2">#F0000000</color>
<color name="white">#FFFFFFFF</color>
<color name="gray">#a9a9a9a9</color>
<color name="green">#228b22</color>
<color name="green_b">#008000</color>
<color name="blue">#40e0d0</color>
<color name="blue_b">#00ced1</color>
</resources>
themes.xml
colorPrimary는 상단바
colorPrimartVariant는 상단 상태바(와이파이, 시간 등)
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.HW4_20211319" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/black</item>
<item name="colorPrimaryVariant">@color/black_2</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>