Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何创建100%自定义对话框片段_Android_Xamarin.android - Fatal编程技术网

Android 如何创建100%自定义对话框片段

Android 如何创建100%自定义对话框片段,android,xamarin.android,Android,Xamarin.android,我想要一个Android对话框,使用完全定制的片段:不包括任何平台对话框主题片段。例如,类似这样的内容: 如何做到这一点?下面的Mono for Android C#代码实现了这一点(但应该很容易移植到Java)。我在安卓2.2(Galaxy S)和安卓4.1(Nexus 7)上进行了测试。唯一需要更改的是用于父视图和对话框视图的布局ID [Activity (MainLauncher = true)] public class TestCustomDialogActi

我想要一个Android对话框,使用完全定制的片段:不包括任何平台对话框主题片段。例如,类似这样的内容:


如何做到这一点?

下面的Mono for Android C#代码实现了这一点(但应该很容易移植到Java)。我在安卓2.2(Galaxy S)和安卓4.1(Nexus 7)上进行了测试。唯一需要更改的是用于父视图和对话框视图的布局ID

[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");
    }        
}

我将Android的完整Mono示例上传到。

下面的代码将帮助您显示全屏对话框,并设置透明颜色

Dialog dialog = new Dialog(this);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
// layout to display
dialog.setContentView(R.layout.about_program_dialog_layout);

// set color transpartent
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

dialog.show();
关于\u程序\u对话框\u layout.xml



谢谢。一旦转换成java,这就为我带来了好处。我必须更改WRAP\u内容以匹配\u父对象,才能使对话框全屏显示。感谢Github上载这是一个对话框,而不是问题中的对话框片段
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#55000000" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="227dp"
        android:text="Dismiss" />

    <TextView
        android:id="@+id/autoCompleteTextView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/button1"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="16dp"
        android:layout_marginRight="63dp"
        android:ems="10"
        android:text="Hello There World" />

</RelativeLayout>