2016-07-26 291 views
1

我試圖做一個全屏警報對話框。但我已經得到這個ScreenShot。請幫助我改進它,完全填滿屏幕。我已經閱讀了很多問題,但是我無法解決這個問題。製作全屏警告對話框

這裏是我的代碼:

// AlertDialog Builder 
    AlertDialog.Builder bmneu = new AlertDialog.Builder(this, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen); 

    // Inflate 
    LayoutInflater inflate = this.getLayoutInflater(); 

    // View 
    View v = inflate.inflate(R.layout.help_archive, null); 

    // Assign view to AlertDialogBuilder 
    bmneu.setView(v); 

    // Alert Dialog 
    AlertDialog alertHelp = bmneu.create(); 

    // Show AlertDialog 
    alertHelp.show(); 

XML代碼(help_archive.xml):

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollView1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#40e9e2f7" > 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/txtHelpArchive1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="در این قسمت بایگانی از موارد خمسی ذخیره شده را مشاهده می کنید." 
     android:gravity="right" 
     android:padding="10dp" 
     android:textColor="#ffffff" 
     android:background="@android:color/transparent" /> 

    <ImageView 
     android:id="@+id/imgHelpArchive1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:src="@drawable/help_archive1" 
     android:padding="10dp" /> 

    <TextView 
     android:id="@+id/txtArchive2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="تاریخ سال خمسی با مشخص بودن، شمسی و یا قمری بودن سال، مشخص شده است. در سمت چپ تصویر نیز برای حذف، تعبیه شده است." 
     android:gravity="right" 
     android:padding="10dp" 
     android:textColor="#ffffff" 
     android:background="@android:color/transparent" /> 

    <ImageView 
     android:id="@+id/imgHelpArchive2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:src="@drawable/help_archive2" 
     android:padding="10dp" /> 

    <TextView 
     android:id="@+id/txtHelpArchive3" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="با فشردن کلیدهای زیر می توانید، می توانید مواردی را که قبلا ذخیره کرده اید، مشاهده و یا ارسال کنید." 
     android:gravity="right" 
     android:padding="10dp" 
     android:textColor="#ffffff" 
     android:background="@android:color/transparent" /> 

    <ImageView 
     android:id="@+id/imgHelpArchive3" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:src="@drawable/help_archive3" 
     android:padding="10dp" /> 

</LinearLayout> 
</ScrollView> 

感謝。

+0

儘量把marginTop /底部到零布局'help_archive'。如果這不起作用,然後嘗試設置爲bmneu。 –

+0

在我的佈局邊距爲零。如何設置bmenu? –

+0

help_archive佈局文件中的值是什麼 – andre3wap

回答

1

你可以做的是創建一個自定義對話框擴展DialogFragment和你在onStart()方法如下:

@Override 
    public void onStart() { 
     super.onStart(); 

     int height = (int)(getResources().getDisplayMetrics().heightPixels); 
     int width = (int)(getResources().getDisplayMetrics().widthPixels); 

     getDialog().getWindow().setLayout(width, height); 
    } 

希望這有助於!如果我不夠清楚,請告訴我。

0

也許這將是有益的:

  AlertDialog.Builder bmneu = new AlertDialog.Builder(this, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen); 

      // Inflate 
      LayoutInflater inflate = getLayoutInflater(); 

      // View 
      View v = inflate.inflate(R.layout.help_archive, null); 

      // Assign view to AlertDialogBuilder 
      bmneu.setView(v); 


      // Alert Dialog 
      AlertDialog alertHelp = bmneu.create(); 

      // Show AlertDialog 
      alertHelp.show(); 

      ScrollView.LayoutParams params = (ScrollView.LayoutParams) v.getLayoutParams(); 
      params.height = getResources().getDisplayMetrics().heightPixels; 
      params.width = getResources().getDisplayMetrics().widthPixels; 
      v.setLayoutParams(params); 

代碼的最後塊設置視圖的寬度和高度(對話框內)

所以,把下面的代碼顯示alertHelp.show()後(記住這v是你的佈局):

  ScrollView.LayoutParams params = (ScrollView.LayoutParams) v.getLayoutParams(); 
      params.height = getResources().getDisplayMetrics().heightPixels; 
      params.width = getResources().getDisplayMetrics().widthPixels; 
      v.setLayoutParams(params); 
+0

通過嘗試此操作,我得到運行時錯誤! –

+0

對不起,我編輯了,我的錯誤。 –

+0

對不起。它無法幫助。我認爲一個alertDialog不能是全屏! –