Tushar Seth
Tushar Seth

Reputation: 613

Creating a slideUp window over the main activity if a button is clicked

I want to create a window which pops up when a button is clicked, in which I can give some buttons to be selected which can be used to provide some data to the main activity.

I tried with Dialog box and Frame layout. Problem with Dialog box is that it doesn't cover the whole screen. Problem with Frame layout using fragment transaction which I am facing is that the main activity's layout is also visible when frame layout comes into picture.

Eg.

enter image description here

But when i click on button to show the window from below:

enter image description here

ie. the image and START button from the activity is also visible. It should partially cover the activity with my fragment window I have tried with giving background color as white in FrameLayout.

Upvotes: 1

Views: 87

Answers (3)

Bö macht Blau
Bö macht Blau

Reputation: 13019

You already tried with a Dialog, so maybe BottomSheetDialogFragment is a good choice for you since it extends from DialogFragment.

There is a Medium blog post with a short example: Using BottomSheetDialogFragment with Material Design Guideline

Since you need a fullscreen Dialog: BottomSheetDialogFragment - How to set expanded height (or min top offset) is an SO post about setting the expanded height of a BottomSheetDialogFragment.

See also the material design guidelines on Modal Bottom Sheets as well as the reference

Upvotes: 1

gpuser
gpuser

Reputation: 1183

Try this way of code to show the window

public void showDefaultDialog() {
final Dialog dialog = new Dialog(MainActivity.this, android.R.style.Theme_Holo_Dialog);
     dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
     dialog.getWindow().getAttributes().windowAnimations = R.style.animWindow;
     dialog.setContentView(R.layout.dialogview);
     dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.WHITE));
     dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,   ViewGroup.LayoutParams.MATCH_PARENT);
}     

put the below line of code in style.xml file

 <style name="animWindow">
     <item name="@android:windowEnterAnimation">@anim/bottom_to_top</item>
     <item name="@android:windowExitAnimation">@anim/top_to_bottom</item>
</style>

put the below line of code in drawable folder

- bottom_to_top.xml

 <?xml version="1.0" encoding="utf-8"?>
     <set xmlns:android="http://schemas.android.com/apk/res/android">
      <translate 
         android:fromYDelta="100%p"
         android:toYDelta="0%p"
         android:fillAfter="true"
         android:duration="700" />
     </set>

- top_to_bottom.xml

 <?xml version="1.0" encoding="utf-8"?>
     <set xmlns:android="http://schemas.android.com/apk/res/android">
      <translate 
         android:fromYDelta="0%p"
         android:toYDelta="100%p"
         android:fillAfter="true"
         android:duration="700" />
     </set>

Upvotes: 1

Hardik Bambhania
Hardik Bambhania

Reputation: 1792

You can use bottom sheet.

Please find below tutorial link that will help you

Android Bpttom sheet medium

Android Bottom sheet mindcor

Let me know, Is it helping you or not +1

Upvotes: 1

Related Questions