0

enter image description hereI have the screen where I need to open the dialog in full screen but it should be above the bottom tab bar.

The code used to make the dialog appear in whole screen is as follows:

WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
dialog.show();
dialog.getWindow().setAttributes(lp);

But this code provides me the dialog in the whole screen hiding the bottom tab bar. Can please anyone help me on this?

As shown in cropped image, I want dialog above the bottom tab bar in full screen.

Siraj Sumra
  • 934
  • 1
  • 11
  • 28
  • i not understand , you want full dialog or full dialog but below tab bar? – Saeid Jan 05 '17 at 14:45
  • where define dialog? in activity or fragment? - and either of top view and bottom tabs are in same class/view/layout? – Saeid Jan 06 '17 at 13:55
  • Defined the dialog in fragment. Top view are in same activity – Siraj Sumra Jan 09 '17 at 07:36
  • so , your dialog defined in fragment and `bottom tab bar` defined in activity , right? – Saeid Jan 09 '17 at 07:41
  • seem your problem is with defined location of dialog , because dialog is defined in fragment and `bottom tab` is out of sight of dialog – Saeid Jan 09 '17 at 07:44
  • There is activity which is enclosing this bottom tab bar with its respective fragments. The fragment in which I want to display the dialog is the 2nd one, as shown in image. Now Whenever I tap on the 2nd tab, It should open the dialog in full screen. But it should not hide the bottom tab bar. – Siraj Sumra Jan 09 '17 at 07:47

2 Answers2

1

Try this,

In onCreate use [this will give you screen height]:-

    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int screenHeight = size.y;

In onResume use [this will give you tab bar height]

 ViewTreeObserver observer = tabBar.getViewTreeObserver();
        observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                int tabBarHeight= tabBar.getHeight();
            tabBar.getViewTreeObserver().removeGlobalOnLayoutListener(
                        this);
            }
        });

Now for our dialog height use [create class variable for screenHeight and tabBarHeight]:-

WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = screenHeight -tabBarHeight;
dialog.show();
dialog.getWindow().setAttributes(lp);
santosh kumar
  • 2,952
  • 1
  • 15
  • 27
  • you can try this . it will help. – santosh kumar Jan 05 '17 at 14:39
  • This will not help as I have to show dialog in whole screen but it should not hide the bottom tab bar. I have edited my question. – Siraj Sumra Jan 06 '17 at 06:45
  • I have modified the answer hope it will solve your problem. – santosh kumar Jan 06 '17 at 07:37
  • Hi @santosh kumar, Thanks for the answer. The answer given by you will solve my issue as a UI perspective. But dialog's main behaviour is that if we click anywhere outside the dialog, First the dialog will close. So even if I am able to achieve this thing in UI manner. It won't help me to click the bottom tab bar and load other fragments. – Siraj Sumra Jan 09 '17 at 07:57
  • you will not be able to click in tab bar before closing the dialog because dialog will be on the foreground and it will not allow you to click background item in any condition. – santosh kumar Jan 09 '17 at 08:50
  • Yes that is the issue with the current approach, Do you have any better suggestion to display this kind of structure? Should I remove dialog completely and use fragment approach or something to display my requirement? – Siraj Sumra Jan 09 '17 at 08:59
  • 1
    fragment approach would be better for this requirement.because dialog will not allow click without closing due to foreground reason – santosh kumar Jan 09 '17 at 09:17
  • Yes exactly, Thanks for your time. Really appreaciated – Siraj Sumra Jan 09 '17 at 09:22
0

This is easy if you want total control over a Dialog just create a custom one. You will need a XML file and a method in what ever Activity you want to use the Custom Dialog Here is the code for the XML and the method below. New XML file RIGHT click res -> New -> XML (near the bottom)-> Layout XML file

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_lightGray"
tools:context="com.example.dwight.pwkeeper.MainActivity">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="84dp"
    android:background="@color/color_darkGray"
    android:minHeight="?attr/actionBarSize">

    <ImageView
        android:id="@+id/imageTB"
        android:layout_width="70dp"
        android:layout_height="wrap_content"
        android:paddingBottom="2dp"
        android:paddingLeft="2dp"
        android:paddingRight="2dp"
        android:paddingTop="4dp"
        android:src="@drawable/lockgold" />

    <TextView
        android:text="@string/app_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/toolbar"
        android:layout_alignParentStart="true"
        android:layout_marginStart="30dp"
        android:layout_marginBottom="20dp"
        android:id="@+id/tvMA"
        android:textStyle="bold"
        android:textColor="@color/color_White"
        android:textSize="28sp" />

</android.support.v7.widget.Toolbar>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/toolbar"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:id="@+id/RLscreen">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Password"
        android:layout_marginLeft="100dp"
        android:layout_marginTop="60dp"
        android:id="@+id/tvPW"
        android:textColor="@android:color/black"
        android:textStyle="bold"
        android:textSize="26sp"/>

    <EditText
        android:id="@+id/etPW"
        android:layout_width="260dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="220dp"
        android:layout_marginTop="50dp"
        android:backgroundTint="@color/color_Black"
        android:cursorVisible="true"
        android:ems="10"
        android:gravity="bottom"
        android:inputType="text"
        android:textColor="@android:color/black"
        android:textSize="26sp"
        android:textStyle="bold" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Confirm Password"
        android:layout_marginTop="140dp"
        android:id="@+id/tvCPW"
        android:textColor="@android:color/black"
        android:textStyle="bold"
        android:textSize="26sp"/>

    <EditText
        android:id="@+id/etCPW"
        android:layout_width="260dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="220dp"
        android:layout_marginTop="130dp"
        android:backgroundTint="@color/color_Black"
        android:ems="10"
        android:inputType="text"
        android:textColor="@android:color/black"
        android:textSize="26sp"
        android:textStyle="bold" />

    <Button
        android:id="@+id/btnSave"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="220dp"
        android:layout_marginTop="220dp"
        android:text="SAVE"
        android:textColor="@color/color_lightGray"
        android:textSize="30sp"
        android:textStyle="bold" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="220dp"
        android:layout_marginTop="220dp"
        android:id="@+id/btnEnter"
        android:textColor="@color/color_lightGray"
        android:textStyle="bold"
        android:textSize="30sp"
        android:visibility="invisible"
        android:onClick="onEnter"
        android:text="ENTER" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="false"
        android:layout_alignParentStart="false"
        android:layout_marginTop="350dp"
        android:src="@drawable/pwkeyb600" />

</RelativeLayout>

    private void doCustom(){
    /* This method uses the custom_dialog.xml file created for greater control over
       the styling of the Custom Alert Dialog for various screen sizes and to be
       able to set the text size of the dialog message text
     */

    final Dialog openDialog = new Dialog(context);
    openDialog.setContentView(R.layout.custom_dialog);
    Button btnYES = (Button)openDialog.findViewById(R.id.btnYES);
    Button btnNO = (Button)openDialog.findViewById(R.id.btnNO);

    // if YES delete Master Password from TABLE_MPW
    btnYES.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Write your code here to invoke YES event
            db = helper.getReadableDatabase();

            String q = "SELECT * FROM masterPW";
            Cursor cursor = db.rawQuery(q,null);
            // Above query gets TABLE_PW data from Col_IDI
            // TABLE_PW will only ever have one row of data

            int rowID = 99;
            if(cursor.moveToFirst()){
                rowID = cursor.getInt(cursor.getColumnIndex(Col_IDI));
                str = cursor.getString(cursor.getColumnIndex(Col_MPW));
            }
            cursor.close();

            // Line of code below WORKS deletes entire TABLE <=====
            // Not a recommended way to re-set the master password
            // db.delete(TABLE_PW, null, null);

            String num = Integer.toString(rowID);

            db.delete(TABLE_PW, Col_IDI + " = ?", new String[] { num });
            db.close();
            openDialog.dismiss();

            Intent intentYY = new Intent(DetailsActivity.this, MainActivity.class );
            startActivity( intentYY );

            Toast.makeText(getApplicationContext(), "Change the Password", Toast.LENGTH_SHORT).show();
        }
    });

    btnNO.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            openDialog.dismiss();

            Intent intent = new Intent( DetailsActivity.this, ListActivity.class );
            startActivity( intent );

            Toast.makeText(getApplicationContext(), "Password NOT Changed", Toast.LENGTH_SHORT).show();
        }
    });

    openDialog.show();
}
Vector
  • 3,066
  • 5
  • 27
  • 54