- CapnAndy
- Feb 27, 2004
-
Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
|
I decided to get into Android development and I'm already pretty good at c# and visual studio, so I got MonoDroid. At first glance, it's super neat. But I want that frigging title bar to go away! I did this: code:[Activity(Label = "AndroidFirst", MainLauncher = true, Icon = "@drawable/icon")]
public class Activity1 : Activity
{
int count = 1;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button>(Resource.Id.HelloButton);
button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
this.Window.AddFlags(WindowManagerFlags.Fullscreen);
this.RequestWindowFeature(WindowFeatures.NoTitle);
}
}
But it fails, and the only error I get is the extremely unhelpful "Android.Util.AndroidRuntimeException:". The Fullscreen flag was working, it just started being a pain in the rear end when I tried requesting no title. What stupidly basic newbie mistake am I making?
|
#
¿
Oct 10, 2012 18:47
|
|
- Adbot
-
ADBOT LOVES YOU
|
|
#
¿
May 5, 2024 15:40
|
|
- CapnAndy
- Feb 27, 2004
-
Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
|
You have to add window flags and request window features before you call setContentView, since it takes those flags into consideration when it creates the layout.
Aha, thank you. I have also discovered themes, which are better I think!
You can use @android:style/Theme.NoTitleBar theme (that Activity attribute seems to have Theme property).
It does, and I can set it programatically too. MonoDroid is keen as poo poo.
|
#
¿
Oct 10, 2012 19:03
|
|
- CapnAndy
- Feb 27, 2004
-
Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
|
Okay, answer another newbie question? I'm still playing with MonoDroid and I want to learn to draw things. I found about making my own view and overriding its OnDraw event, but that's okay for, y'know, drawing something once and then it never moves again, and also I lose Main.axml which would be a shame. I want to do something really basic, like draw a box and have it change colors or resize every time I click a button or on a Timer tick.
It seems like what I need to do is get the canvas object of the current ContentView, right? Then I could just pass that into a function and have it draw on the canvas. Am I right so far, and if I am, how do I friggin' do that?
|
#
¿
Oct 22, 2012 15:50
|
|
- CapnAndy
- Feb 27, 2004
-
Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
|
You'll need to get the surface holder using getHolder(), then you can use the lock canvas method if you are working from a separate thread.
I don't follow. I lock the canvas so nothing else can touch it, but I still don't have access to the canvas itself, so how can I draw on it?
Maybe what I've actually written will help: code:public class Activity1 : Activity
{
int count = 1;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// this.Window.AddFlags(WindowManagerFlags.Fullscreen);
// this.RequestWindowFeature(WindowFeatures.NoTitle);
SetTheme(Android.Resource.Style.ThemeLightNoTitleBarFullScreen);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button>(Resource.Id.HelloButton);
SurfaceView view = FindViewById<SurfaceView>(Resource.Id.DrawingView);
button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); view.Invalidate(); };
view.Draw(drawSquare();
view.Invalidate();
}
public Canvas drawSquare()
{
Canvas result = new Canvas();
Paint paint = new Paint();
paint.Color = Color.Yellow;
result.DrawRect(0, 0, 250, 250, paint);
result.Save();
return result;
}
}
This doesn't work.
CapnAndy fucked around with this message at 20:43 on Oct 22, 2012
|
#
¿
Oct 22, 2012 20:39
|
|
- CapnAndy
- Feb 27, 2004
-
Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
|
You don't create the canvas directly, you let the OS generate the canvas when you call lockCanvas().
Oh poo poo, I didn't realize it did that. I went with the wussy way just to get something working by just making my own custom View so that I could override its OnDraw method, and then pulled a lot of bullshit (giving the view public settable variables that OnDraw paid attention to) to make sure I could manipulate the view with outside events. I'm gonna try that instead, it'll be cleaner.
|
#
¿
Oct 25, 2012 22:11
|
|
- CapnAndy
- Feb 27, 2004
-
Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
|
For now you can just check to see if the canvas you get from lockCanvas() is null before you use it.
Okay, it's been a bit because I had actual projects to do and those come before learning new stuff, but I'm back to this, and the canvas I get from lockCanvas() is always null. I tried doing this: C# code:SurfaceView surface = new SurfaceView(this);
layout.AddView(surface);
Canvas c = surface.Holder.LockCanvas();
c.DrawColor(Color.Green);
surface.Holder.UnlockCanvasAndPost(c);
But that fails because c is null. If I do this:C# code:SurfaceView surface = new SurfaceView(this);
layout.AddView(surface);
Canvas c = surface.Holder.LockCanvas();
c = new Canvas();
c.DrawColor(Color.Green);
surface.Holder.UnlockCanvasAndPost(c);
It fails on the UnlockCanvasAndPost, presumably because c has a Height and Width of 0. I'm guessing about why this one's failing, though. All I get is "Java.Lang.IllegalArgumentException".
|
#
¿
Nov 1, 2012 18:25
|
|
- Adbot
-
ADBOT LOVES YOU
|
|
#
¿
May 5, 2024 15:40
|
|
- CapnAndy
- Feb 27, 2004
-
Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
|
Yeah, but on the other hand I need to do it in MonoDroid, because that's what I got told to learn, everything else we do is in Visual Studio, and that way it can be easily ported to iOS with MonoTouch. So MonoDroid it is. I am using an XML layout, though! I think I am! I've got a Main.axml, it's very useful.
Using lockCanvas after OnCreate gets done running does work, so you were right. I'm gonna play with how that works vs. an overrided OnDraw.
I'm sorry I'm a pain in the rear end, by the way.
edit: When I change my SampleView from extending View to extending SurfaceView, suddenly the OnDraw override stops firing. How odd. SurfaceViews don't use OnDraw?
edit edit: Fixed that one on my own. Apparently when you extend a SurfaceView it defaults to WillNotDraw = true. Go figure. At least I'm learning! Unfortunately, OnDraw apparently overrides whatever I did in LockCanvas. So, one step forward, one step right back.
CapnAndy fucked around with this message at 21:40 on Nov 1, 2012
|
#
¿
Nov 1, 2012 21:13
|
|