Foggy day

Android(java) - Activity popup(background dim) 본문

Android

Android(java) - Activity popup(background dim)

jinhan38 2021. 3. 4. 14:55

 

 

 

sample video

 

 

 

 

 

 

 

 

1. popup_activity_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:gravity="center"
    android:orientation="vertical">


    <FrameLayout
        android:layout_width="300dp"
        android:layout_height="400dp"
        android:background="@color/white">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Activity Popup"
            android:textColor="@color/black"
            android:textSize="30dp" />


        <TextView
            android:id="@+id/tvOK"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_gravity="bottom"
            android:background="#FFE0E0E0"
            android:gravity="center"
            android:text="OK"
            android:textColor="@color/black"
            android:textSize="20dp" />


    </FrameLayout>


</LinearLayout>

 

 

 

2. ShowPopup.java

public class ShowPopup extends AppCompatActivity {

    private PopupActivityLayoutBinding b;

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

        b = PopupActivityLayoutBinding.inflate(getLayoutInflater());
        setContentView(b.getRoot());

        //If you want to fix orientation, input this code
        try {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        } catch (IllegalStateException ignore) {

        }

        b.tvOK.setOnClickListener(view -> finish());

    }
}

 

 

 

3. PopupLayoutActivity

class PopupLayoutActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_popup_layout)

        tvShowPopup.setOnClickListener {
            startActivity(Intent(this, ShowPopup::class.java))
        }
    }
}