设为首页 加入收藏

TOP

C#-Xamarin的Android项目开发(一)——创建项目(二)
2019-09-01 23:25:25 】 浏览:87
Tags:C#-Xamarin Android 项目开发 创建 项目
> { if (cancelCallback != null) { cancelCallback(dialog); } })); //builder.SetNeutralButton("稍后提醒", new EventHandler<DialogClickEventArgs>((s, e) => { })); cdialog = builder.Create();//构建dialog对象 return cdialog; } public void ShowAlert(string msg, Action<AlertDialog> comfirmCallback = null, Action<AlertDialog> cancelCallback = null) { if (comfirmCallback == null) { cancelCallback = (d) => { dialog.Dismiss(); }; } if (cancelCallback == null) { cancelCallback = (d) => { dialog.Dismiss(); }; } dialog = InitDialog(msg, comfirmCallback, cancelCallback); if (dialog != null && !dialog.IsShowing) { dialog.Show(); } } public void NotifyMessage(string message, string title = "消息") { NotificationManager manager = (NotificationManager)GetSystemService(Context.NotificationService); // 在Android进行通知处理,首先需要重系统哪里获得通知管理器NotificationManager,它是一个系统Service。 PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0, new Intent(this, typeof(MainActivity)), 0); Notification notify1 = new Notification(); notify1.Icon = Resource.Drawable.logo; notify1.TickerText = JaveString("您有新短消息,请注意查收!"); notify1.When = DateTime.Now.ToFileTime(); notify1.SetLatestEventInfo(this, title, message, pendingIntent); notify1.Number = 1; notify1.Flags |= NotificationFlags.AutoCancel; // FLAG_AUTO_CANCEL表明当通知被用户点击时,通知将被清除。 // 通过通知管理器来发起通知。如果id不同,则每click,在statu那里增加一个提示 manager.Notify(1, notify1); } public static Java.Lang.String JaveString(string str) { return new Java.Lang.String("您有新短消息,请注意查收!"); } #endregion #region 寻找资源 public T FindControl<T>(string name) where T : View { return FindViewById<T>(GetCode(name)); } public T FindControl<T>(string name, Action callBack) where T : View { View view = FindViewById<T>(GetCode(name)); view.Click += (s, e) => { callBack(); }; return FindViewById<T>(GetCode(name)); } public int GetCode(string name) { var R = this.Resources; var code = (typeof(Resource.Id)).GetFields().FirstOrDefault(f => f.Name == name).GetValue(R); return (int)code; } #endregion #region 异步调用 public void AsyncLoad(Action action) { IAsyncResult result = action.BeginInvoke((iar) => { }, null); } public void AsyncLoad(Action action, Action callback) { IAsyncResult result = action.BeginInvoke((iar) => { this.RunOnUiThread(callback); }, null); } public void AsyncLoad<T>(Action<T> action, T para, Action callback) { IAsyncResult result = action.BeginInvoke(para, (iar) => { this.RunOnUiThread(callback); }, null); } public void RunOnUi(Action action) { ((BaseActivity)this).RunOnUiThread(() => { action(); });//回UI线程 } #endregion #region 获取数据 public void GetRest(string url, Action<JsonValue> callback) { Task.Run(() => { try { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url)); request.ContentType = "application/json"; request.Method = "GET"; using (WebResponse response = request.GetResponse()) { using (Stream stream = response.GetResponseStream()) { JsonValue jsonDoc = Json
首页 上一页 1 2 3 4 下一页 尾页 2/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Android For OpenCV的环境搭建 下一篇keyboard dialog 仿微博表情键盘..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目