Mã Mono cho Android C sau đây thực hiện thủ thuật (nhưng phải dễ dàng chuyển sang Java). Tôi đã thử nghiệm trên Android 2.2 (Galaxy S) và Android 4.1 (Nexus 7). Điều duy nhất bạn cần thay đổi là ID bố cục được sử dụng cho chế độ xem chính và chế độ xem hộp thoại.
[Activity (MainLauncher = true)]
public class TestCustomDialogActivity : FragmentActivity
{
public class MyDialogFragment : Android.Support.V4.App.DialogFragment
{
public override Android.Views.View OnCreateView(Android.Views.LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Android 3.x+ still wants to show title: disable
Dialog.Window.RequestFeature(WindowFeatures.NoTitle);
// CHANGE TO YOUR DIALOG LAYOUT or VIEW CREATION CODE
return inflater.Inflate(Resource.Layout.MyLayout, container, true);
}
public override void OnResume()
{
// Auto size the dialog based on it's contents
Dialog.Window.SetLayout(LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent);
// Make sure there is no background behind our view
Dialog.Window.SetBackgroundDrawable(new ColorDrawable(Color.Transparent));
// Disable standard dialog styling/frame/theme: our custom view should create full UI
SetStyle(Android.Support.V4.App.DialogFragment.StyleNoFrame, Android.Resource.Style.Theme);
base.OnResume();
}
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// CHANGE TO YOUR MAIN SCREEN
SetContentView(Resource.Layout.MyDialog);
var dialog = new MyDialogFragment();
dialog.Show(SupportFragmentManager, "dialog");
}
}
Tôi đã tải lên một mẫu đơn đầy đủ cho Android lên https://github.com/t9mike/CustomDialogFragmentSample.
Cảm ơn. Sau khi chuyển đổi sang java này đã làm các trick cho tôi. Tôi đã phải thay đổi WRAP_CONTENT thành MATCH_PARENT để có được hộp thoại hiển thị toàn màn hình. – speedynomads
Cảm ơn Github đã tải lên – Signcodeindie