欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android中DialogFragment自定義背景與寬高的方法

 更新時間:2017年08月29日 10:12:19   作者:RustFisher  
DialogFragment 彈出框默認(rèn)是在屏幕的中央,左右還有留白,那么如何自定義背景和寬高呢?下面這篇文章就來給大家介紹了關(guān)于Android中DialogFragment自定義背景與寬高的方法,需要的朋友可以參考下。

介紹

DialogFragment在android 3.0時被引入。是一種特殊的Fragment,用于在Activity的內(nèi)容之上展示一個模態(tài)的對話框。典型的用于:展示警告框,輸入框,確認(rèn)框等等。

在DialogFragment產(chǎn)生之前,我們創(chuàng)建對話框:一般采用AlertDialog和Dialog。注:官方不推薦直接使用Dialog創(chuàng)建對話框。

本文主要給大家介紹了關(guān)于Android中DialogFragment自定義背景與寬高的相關(guān)內(nèi)容,分享出來供大家參考學(xué)習(xí),下面話不多說了,來一起看看詳細(xì)的介紹吧。

自定義方法如下:

先申請無標(biāo)題欄

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
 getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
// ......
}

然后在onStart方法里重新指定寬高

先設(shè)置透明背景,然后通過DisplayMetrics設(shè)置寬高。

@Override
public void onStart() {
 super.onStart();
 Window window = getDialog().getWindow();
 window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
 WindowManager.LayoutParams windowParams = window.getAttributes();
 windowParams.dimAmount = 0.0f;
 windowParams.y = 100;
 window.setAttributes(windowParams);
 Dialog dialog = getDialog();
 if (dialog != null) {
  DisplayMetrics dm = new DisplayMetrics();
  getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
  dialog.getWindow().setLayout((int) (dm.widthPixels * 0.9), (int) (dm.heightPixels * 0.76));
 }
}

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。

相關(guān)文章

最新評論