我正在尝试显示几乎全屏的DialogFragment.但我不知道怎么做不到.
我展示Fragment的方式直接来自android开发者文档
FragmentManager f = ((Activity)getContext()).getFragmentManager();
FragmentTransaction ft = f.beginTransaction();
Fragment prev = f.findFragmentByTag("dialog");
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
// Create and show the dialog.
DialogFragment newFragment = new DetailsDialogFragment();
newFragment.show(ft, "dialog");
Run Code Online (Sandbox Code Playgroud)
我知道天真地尝试将片段中的RelativeLayout设置为fill_parent和一些minWidth和minHeight.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="1000px"
android:minHeight="600px"
android:background="#ff0000">
Run Code Online (Sandbox Code Playgroud)
我知道期望DialogFragment填满屏幕的大部分.但我似乎只是垂直调整大小,但只是水平固定宽度.
我还尝试在代码中设置窗口属性,如下所示:http://groups.google.com/group/android-developers/browse_thread/thread/f0bb813f643604ec.但这也没有帮助.
我可能误解了Android处理Dialogs的方式,因为我对它不熟悉.我怎么能这样做?有没有其他方法可以实现我的目标?
Android设备:
华硕EeePad Transformer
Android 3.0.1
更新: 我现在设法将其全屏显示,片段中包含以下代码
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NO_FRAME, android.R.style.Theme_Holo_Light);
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这不是我想要的.我肯定需要在对话框周围显示一个小"填充"来显示背景.
任何想法如何实现?
我正在创建一个显示在操作栏下方的自定义DialogFragment.到目前为止一切都很好.对话框片段的布局参数用于match_parent宽度和wrap_content高度.
我尝试了所有解决方案,包括设置布局参数.width以及获取显示大小和删除主题.然而,无论在对话框的左侧,右侧和顶侧是否有少量空间是不可见的.我需要知道如何删除这个空间,以便它实际上匹配屏幕的宽度,并希望摆脱顶部填充.
我已经Dialog在我的Andorid 应用程序中用于显示广告.但是我必须显示这个Dialog大约50dp来自buttom的顶部所以我认为我们应该设置DialogGravity buttom并设置它的buttom边距50dp.但我不能使用保证金.所以Dialog请建议我如何解决这个问题.
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/popup_element"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/dialogback"
android:orientation="vertical" >
<WebView
android:id="@+id/webView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
Java的:
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
LayoutInflater inflator = (LayoutInflater) getApplicationContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflator.inflate(R.layout.ad, null, false);
dialog.setContentView(view);
dialog.getWindow().setGravity(Gravity.BOTTOM);
dialog.setCancelable(true);
WebView webView = (WebView) dialog.findViewById(R.id.webView);
webView.loadUrl("");
webView.setWebViewClient(new MyWebViewClient());
webView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
dialog.show();
Run Code Online (Sandbox Code Playgroud)