How to make a dialog slide from bottom to middle of screen in android

后端 未结 8 2528
别跟我提以往
别跟我提以往 2020-11-30 17:10

I want to show a dialog on my activity with animation. My dialog will slide from bottom of activity to middle of activity.

/****Edit****/

I\'m sorry for my q

8条回答
  •  醉酒成梦
    2020-11-30 18:12

    For this, you need 2 animations and put this in the res/anim folder

    1. slide_up_dialog.xml
    
    
    

    2.slide_out_down.xml

    
    
    

    Now you have to create a custom style in style.xml

    
    

    Next is to extend the android Theme. Dialog theme in the same style.xml and give the reference to the custom style we created.

    
        
    

    And finally, call this style when you create the dialog like this.

    dialog = new Dialog(new ContextThemeWrapper(this, R.style.DialogSlideAnim));
    

    yep...Now the Dialog is ready to slide.....!!

    Update:

    As @MichealP suggested, this will place the window at the bottom

    getWindow().setGravity(Gravity.BOTTOM); 
    

    and modify the style to remove tittle and background

    @null 
    @null 
    true
    

    As @sikni8 suggested this will make the black border transparent

    getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    

提交回复
热议问题