2016-07-26 284 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不能是全屏! –