Xamarin.Form 弹出自定义对话框
来源:互联网 发布:乐视2pro相机优化 编辑:程序博客网 时间:2024/05/18 00:43
第一步先在MainActivity.cs 文件把当前Activity 获取。注意:Xamarin.Form是可以直接调用安卓原生方法的,有些伙伴可能比较迷茫
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity{protected override void OnCreate(Bundle bundle){TabLayoutResource = Resource.Layout.Tabbar;ToolbarResource = Resource.Layout.Toolbar;base.OnCreate(bundle);global::Xamarin.Forms.Forms.Init(this, bundle);//获取当前的活动视图LoadApplication(new App());}}
然后创建Layout文件,xml代码如下:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:minWidth="200dp" android:padding="10dp" android:paddingTop="30dp" android:paddingBottom="30dp" android:layout_width="match_parent" android:layout_height="match_parent"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="小区名称" android:minHeight="45dp" /> <ImageView android:src="@android:color/holo_blue_light" android:layout_width="match_parent" android:layout_height="200dp" /> <Button android:text="提交" android:minHeight="45dp" android:layout_width="match_parent" android:layout_height="wrap_content" /></LinearLayout>
然后再创建对应的cs文件;using Android.App;using Android.Content;using Lierda.HandApp.Droid;public class CreateAreaInformation : Dialog{public Context context { get; private set; }public CreateAreaInformation(Context context) : base(context){this.context = context;}protected override void OnCreate(Android.OS.Bundle savedInstanceState){this.SetContentView(Resource.Layout.CreateAreaInformationDialog);var dialogWindow = this.Window;var act = context as Activity;var manager = act.WindowManager;var display = manager.DefaultDisplay;var attr = dialogWindow.Attributes;#pragma warning disable CS0618 // Type or member is obsoleteattr.Width = (int)(display.Width * 0.8);#pragma warning restore CS0618 // Type or member is obsoletedialogWindow.Attributes = attr;base.OnCreate(savedInstanceState);}}
这里需要继承Dialog 类,注意命名空间,别弄错了。
最后便是调用了。
/// <summary> /// 单击新增小区 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void Handle_Clicked(object sender, System.EventArgs e) {
//注意,Xamarin.Forms.Forms.Context便是当前活动。 CreateAreaInformation createAreaInformation = new CreateAreaInformation(Xamarin.Forms.Forms.Context);createAreaInformation.Show(); }
效果如下:
阅读全文
1 0
- Xamarin.Form 弹出自定义对话框
- 弹出自定义模式对话框
- 自定义弹出对话框
- c# 弹出自定义对话框
- Android弹出自定义对话框
- AlertDialog自定义弹出对话框
- 自定义弹出对话框
- Xamarin.iOS 自定义样式的弹出窗
- android 弹出对话框 弹出自定义对话框
- 【工具类】自定义弹出对话框
- Popup弹出自定义布局对话框
- ios 自定义弹出对话框效果
- android自定义底部弹出对话框
- 微信小程序-弹出自定义对话框
- android自定义对话框和弹出框
- Android中Dialog实现自定义弹出对话框
- 【android学习】自定义的Builder弹出对话框
- 自定义一个View作为弹出对话框
- [AHK]按住左键可以移动鼠标下的窗口
- MyEclipse 10破解方法及下载地址
- vue动画
- javaEE中的spring配置笔记
- 每天一python 题 0000
- Xamarin.Form 弹出自定义对话框
- android 退出系统的解决办法
- 数据库:事务
- mysql触发器作用及用法
- 处理vue渲染前的显示问题
- UVA 323 Jury Compromise——01背包变形
- codility CountSemiprimes
- 欢迎使用CSDN-markdown编辑器
- MyBatis --- 动态SQL、缓存机制