如何将getApplication从java转换为monodroid?

时间:2013-09-14 08:00:52

标签: view mono xamarin.android floating

我有一个关于从web上浮动视图的java项目。我试图把它翻译成monodroid,但我失败了,因为在功能上,我不知道怎么写monodroid。

java代码在http://www.xsmile.net/file/FloatViewDemo.rar

namespace MonoFloatView
{
    [Activity(Label = "MonoFloatView", MainLauncher = true, Icon = "@drawable/icon")]
    public class MyFloatViewActivity : Activity
    {

        private IWindowManager wm = null;
        private WindowManagerLayoutParams wmParams = null;

        private MyFloatView myFV = null;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);
            createView();

            // Create your application here
        }

        private void createView()
        {
            //myFV = new MyFloatView(getApplicationContext());   //java
            myFV = new MyFloatView(ApplicationContext);
            myFV.SetImageResource(Resource.Drawable.Icon);
            //wm = (WindowManager)getApplicationContext().getSystemService("window");
            //http://stackoverflow.com/questions/13634835/monodroid-screen-dimensions
            //i get some tip from url above.
            wm = GetSystemService(Activity.WindowService).JavaCast<IWindowManager>();

            //i don't know the getApplication, how to write in monodroid?
            wmParams = ((MyApplication)getApplication()).getMywmParams();

            wmParams.Type = LayoutParams.TYPE_PHONE;   
            wmParams.Format = PixelFormat.RGBA_8888; 

            wmParams.Flags = LayoutParams.FLAG_NOT_TOUCH_MODAL
                              | LayoutParams.FLAG_NOT_FOCUSABLE;

            wmParams.Gravity = Gravity.LEFT | Gravity.TOP;  
            wmParams.X = 0;
            wmParams.Y = 0;

            wmParams.Width = 40;
            wmParams.Height = 40;

            wm.AddView(myFV, wmParams);

        }

        public override void onDestroy()
        {
            base.OnDestroy();
            wm.RemoveView(myFV);
        }
    }
}

1 个答案:

答案 0 :(得分:1)

如果您参与活动,则应该可以使用:

this.Application