안드로이드 다이얼로그 위치 변경 (Top, Center, Bottom)하기

 

 계발에서 개발까지 

 

 

다이얼로그 위치변경하기

다이얼로그의 위치를 변경하는 방법입니다. 버튼클릭으로 다이얼로그를 띄우고 위치를 변경해보겠습니다.

 

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:gravity="center"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/btn"
        android:text="다이얼로그"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>

 

MainActivity.java

 

 findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setTitle("제목").setMessage("내용");
                AlertDialog alertDialog  = builder.create();
//                alertDialog.getWindow().setGravity(Gravity.TOP);      다이얼로그 상단
//                alertDialog.getWindow().setGravity(Gravity.CENTER);   다이얼로그 중앙
//                alertDialog.getWindow().setGravity(Gravity.BOTTOM);   다이얼로그 하단
                alertDialog.show();


            }
        });

 

수고하셨습니다 ★

더 많은 정보

 https://deumdroid.tistory.com/ 

 

 

댓글

Designed by JB FACTORY