Android: How to get a modal dialog or similar modal behavior?

后端 未结 11 1912
暗喜
暗喜 2020-12-01 05:17

These days I\'m working on simulating modal dialog in Android. I\'ve googled a lot, there\'s much discussions but sadly there\'s not much options to get it modal. Here\'s so

11条回答
  •  抹茶落季
    2020-12-01 05:51

    This works for me: create an Activity as your dialog. Then,

    1. Add this to your manifest for the activity:

      android:theme="@android:style/Theme.Dialog"

    2. Add this to onCreate of your activity

      setFinishOnTouchOutside (false);

    3. Override onBackPressed in your activity:

      @Override public void onBackPressed() { // prevent "back" from leaving this activity }

    The first gives the activity the dialog look. The latter two make it behave like a modal dialog.

提交回复
热议问题