我创建了一个要用作错误消息的视图。
如果手机没有互联网连接(移动数据或wifi),我想在我的应用程序中显示一条错误消息,以便用户知道从那时起的所有内容都将保存在本地(而不是在服务器上)。
这里的问题是,我希望即使用户从一个活动转到另一个活动,此消息也能保持同步。
我尝试在WindowManager上使用对话框和LinearLayout。没用。
这就是我所做的。
public void noConnectionLayout()
{
LinearLayout mainLayout = new LinearLayout (this.ApplicationContext);
mainLayout.Clickable = false;
mainLayout.Focusable = false;
mainLayout.FocusableInTouchMode = false;
mainLayout.LongClickable = false;
mainLayout.SetBackgroundColor (Android.Graphics.Color.Red);
mainLayout.Orientation = Orientation.Vertical;
var spaceFromTopPara = (int) (65 * this.Resources.DisplayMetrics.Density);
var layoutHeight = (int)(25 * this.Resources.DisplayMetrics.Density);
WindowManagerLayoutParams windowLayoutParams = new WindowManagerLayoutParams (
ViewGroup.LayoutParams.MatchParent,
layoutHeight,
WindowManagerTypes.SystemError,
WindowManagerFlags.NotTouchModal | WindowManagerFlags.NotFocusable,
Format.Translucent);
windowLayoutParams.ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait;
windowLayoutParams.Gravity = GravityFlags.Top;
windowLayoutParams.Y = spaceFromTopPara;
TextView textNoConnectionMesg = new TextView (this);
textNoConnectionMesg.Text = "No Connection available.";
textNoConnectionMesg.SetTypeface (this.latoFont, TypefaceStyle.Normal);
textNoConnectionMesg.LayoutParameters = new ViewGroup.LayoutParams (ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
textNoConnectionMesg.Gravity = GravityFlags.Center;
textNoConnectionMesg.SetTextSize (Android.Util.ComplexUnitType.Dip, 14f);
textNoConnectionMesg.SetBackgroundColor (Android.Graphics.Color.Transparent);
textNoConnectionMesg.SetTextColor (Android.Graphics.Color.White);
mainLayout.AddView (textNoConnectionMesg);
WindowManager.AddView (mainLayout, windowLayoutParams);
}
当活动更改时,视图就会消失。
我能在这里做什么?
谢谢你的时间。
对话框本质上与活动相关联。您的用户甚至可以在显示对话框的活动之间导航,这似乎很奇怪。如果要允许导航并在每个屏幕上显示连接状态对话框,则需要显示对话框,例如,所有其他活动扩展的基本活动的启动。