Android

Android 커스텀 다이얼로그

Machine_웅 2021. 1. 21. 12:20
728x90
반응형

activity_test.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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Test">

  <TextView
      android:text="테스트 다이얼로그 !! "
      android:layout_width="match_parent"
      android:layout_height="wrap_content"/>

  </LinearLayout>
  

 

Test.class

package kr.co.eoapps.test_module;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Window;

public class Test extends Dialog {

    Context context;
    public Test(@NonNull Context context) {
        super(context);
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);        //상단 타이틀 제거
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));        //배경 투명
        setCanceledOnTouchOutside(false);        //배경 터치 닫기 기능 사용유무
        setContentView(R.layout.activity_test);
    }
}

 

사용방법

     Test dialog = new Test(context);
                dialog.show();
728x90
반응형