2017-01-05 4 views
0

enter image description here У меня есть экран, где мне нужно открыть диалог в полноэкранном режиме, но он должен быть над нижней панелью вкладок.Как установить диалог в полноэкранном режиме над нижней панелью вкладок?

Код, используемый, чтобы сделать диалоговое окно появится в полноэкранном режиме выглядит следующим образом:

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); 

Но этот код обеспечивает мне диалог в полноэкранном режиме, скрывающую нижнюю панель вкладок. Может ли кто-нибудь помочь мне в этом?

Как показано в обрезанном изображении, я хочу, чтобы диалоговое окно над нижней панелью вкладок отображалось в полноэкранном режиме.

+0

я не понимаю, вы хотите иметь полный диалог или полный диалог, но ниже вкладки бар? – Saeid

+0

где определить диалог? в деятельности или фрагменте? - и ни один из верхних и нижних вкладок в одном классе/представлении/макете? – Saeid

+0

Определено диалоговое окно в фрагменте. Вид сверху в том же самом действии –

ответ

1

Попробуйте это,

В OnCreate использовать [это даст вам экран высоты]: -

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

В onResume использовать [это даст вам панель вкладок высота]

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

Теперь для нашей высоты диалога используйте [create class variable для screenHeight и 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); 
+0

вы можете попробовать. это поможет. –

+0

Это не поможет, поскольку я должен показать диалог на весь экран, но он не должен скрывать нижнюю панель вкладок. Я отредактировал мой вопрос. –

+0

Я изменил ответ, надеюсь, что он решит вашу проблему. –

0

Это легко, если вы хотите, чтобы полный контроль над диалогом создавал пользовательский. Вам понадобится XML-файл и метод, в котором когда-либо выполнялось действие, которое вы хотите использовать Custom Dialog. Ниже приведен код для XML и метод ниже. Новый файл XML щелкните правой кнопкой мыши Рез -> New -> XML (в нижней) -> Layout XML файл

<?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(); 
} 
Смежные вопросы