티스토리 뷰
build.gradle (Module: app)
dependencies {
implementation 'com.google.android.material:material:1.1.0'
}
BottomSheetDialog 는 머티리얼 디자인이므로 의존성 추가
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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">
<Button
android:id="@+id/btnClick"
android:layout_width="200dp"
android:layout_height="80dp"
android:text="클릭"
android:textSize="30dp"
android:textColor="#FFFFFF"
android:textStyle="bold"
android:background="#FF7F00"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
bottom_sheet.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:gravity="center"
android:padding="4dp"
android:background="#FF7F00">
<TextView
android:layout_width="320dp"
android:layout_height="160dp"
android:text="혀가 길지 않은 개발자"
android:textSize="28dp"
android:textColor="#FFFFFF"
android:textStyle="bold"
android:gravity="center"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:padding="20dp">
<Button
android:id="@+id/btnOK"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:text="확인"
android:textSize="16dp"
android:textStyle="italic|bold"
android:textColor="#FF7F00"
android:background="#FFFFFF" />
<Button
android:id="@+id/btnClose"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:text="닫기"
android:textSize="16dp"
android:textStyle="italic|bold"
android:layout_marginLeft="8dp"
android:textColor="#FF7F00"
android:background="#FFFFFF" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
BottomSheetFragment.java
package com.jwsoft.javaproject;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
public class BottomSheetFragment extends BottomSheetDialogFragment {
Context context;
public BottomSheetFragment(Context context) {
this.context = context;
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.bottom_sheet, container, false);
Button btnOK = view.findViewById(R.id.btnOK);
btnOK.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, "확인", Toast.LENGTH_SHORT).show();
dismiss();
}
});
Button btnClose = view.findViewById(R.id.btnClose);
btnClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, "닫기", Toast.LENGTH_SHORT).show();
dismiss();
}
});
return view;
}
}
MainActivity.java
package com.jwsoft.javaproject;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button btnClick;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnClick = findViewById(R.id.btnClick);
final BottomSheetFragment bottomSheetFragment = new BottomSheetFragment(getApplicationContext());
btnClick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bottomSheetFragment.show(getSupportFragmentManager(), bottomSheetFragment.getTag());
}
});
}
}
'Android > Java' 카테고리의 다른 글
[Java] FrameLayout (0) | 2020.07.02 |
---|---|
[Java] Fragment (0) | 2020.07.02 |
[Java] BottomSheetDialog (0) | 2020.07.01 |
[Java] SharedPreferences + Singleton Pattern (0) | 2020.06.30 |
[Java] Handler vs runOnUiThread vs AsyncTask (0) | 2020.06.29 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- recyclerview
- Design Pattern
- activity
- java
- 혀가 길지 않은 개발자
- Intent
- James Kim
- MVVM
- Kotlin
- XML
- coroutine
- Vue.js #Vue.js + javascript
- handler
- CoordinatorLayout
- Android
- TabLayout
- Architecture Pattern
- JSONObject
- DataBinding
- View
- Livedata
- ViewModel
- ViewPager2
- 안드로이드
- 안드로이드 #코틀린 #Android #Kotlin
- 자바
- fragment
- 코틀린
- ArrayList
- JSONArray
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함