티스토리 뷰
common_toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="@+id/btnBack"
android:layout_width="26dp"
android:layout_height="35dp"
android:layout_gravity="center_vertical"
android:background="@drawable/back" />
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Toolbar"
android:textSize="24dp"
android:layout_gravity="center"/>
<ImageButton
android:id="@+id/btnForward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@drawable/forward" />
</FrameLayout>
</androidx.appcompat.widget.Toolbar>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<include
android:id="@+id/includeMain"
layout="@layout/common_toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Main"
android:textSize="30dp"
android:textStyle="bold|italic"
android:layout_gravity="center"/>
</FrameLayout>
</LinearLayout>
activity_second.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".SecondActivity">
<include
android:id="@+id/includeSecond"
layout="@layout/common_toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Second"
android:textSize="30dp"
android:textStyle="bold|italic"
android:layout_gravity="center"/>
</FrameLayout>
</LinearLayout>
activity_third.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ThirdActivity">
<include
android:id="@+id/includeThird"
layout="@layout/common_toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Third"
android:textSize="30dp"
android:textStyle="bold|italic"
android:layout_gravity="center"/>
</FrameLayout>
</LinearLayout>
ThirdActivity.java
package com.jwsoft.javaproject;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
public class ThirdActivity extends AppCompatActivity {
private ImageButton btnBack;
private ImageButton btnForward;
private TextView tvName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_third);
btnBack = findViewById(R.id.btnBack);
btnForward = findViewById(R.id.btnForward);
tvName = findViewById(R.id.tvName);
tvName.setText("Third");
btnForward.setVisibility(View.INVISIBLE);
btnBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(), SecondActivity.class));
finish();
}
});
}
}
SecondActivity.java
package com.jwsoft.javaproject;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
public class SecondActivity extends AppCompatActivity {
private ImageButton btnBack;
private ImageButton btnForward;
private TextView tvName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
btnBack = findViewById(R.id.btnBack);
btnForward = findViewById(R.id.btnForward);
tvName = findViewById(R.id.tvName);
tvName.setText("Second");
btnBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(), MainActivity.class));
finish();
}
});
btnForward.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(), ThirdActivity.class));
finish();
}
});
}
}
MainActivity.java
package com.jwsoft.javaproject;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private ImageButton btnBack;
private ImageButton btnForward;
private TextView tvName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnBack = findViewById(R.id.btnBack);
btnForward = findViewById(R.id.btnForward);
tvName = findViewById(R.id.tvName);
tvName.setText("Main");
btnBack.setVisibility(View.INVISIBLE);
btnForward.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(), SecondActivity.class));
finish();
}
});
}
}
'Android > Java' 카테고리의 다른 글
[Java] enum (0) | 2020.08.07 |
---|---|
[Java] Generics (2) (0) | 2020.08.06 |
[Java] ImageView 타원화 (0) | 2020.08.04 |
[Java] CoordinatorLayout + ViewPager2 + TabLayout (0) | 2020.08.03 |
[Java] import com.google.gson.* (0) | 2020.07.31 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- DataBinding
- java
- activity
- XML
- JSONArray
- Kotlin
- JSONObject
- 혀가 길지 않은 개발자
- James Kim
- MVVM
- CoordinatorLayout
- handler
- Architecture Pattern
- Android
- ViewPager2
- 안드로이드 #코틀린 #Android #Kotlin
- TabLayout
- fragment
- Intent
- recyclerview
- 안드로이드
- Vue.js #Vue.js + javascript
- View
- Design Pattern
- ArrayList
- 코틀린
- Livedata
- 자바
- coroutine
- ViewModel
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함