[Android game development one] sets full screen and simple painting graphics

Source: Internet
Author: User

 

Directly run the Code:

Package com. himi;

Import android. app. Activity;

Import android. OS. Bundle;

Import android. view. Window;

Import android. view. WindowManager;

Public class MainActivity extends Activity {

/** Called when the activity is first created .*/

@ Override

Public void onCreate (Bundle savedInstanceState ){

Super. onCreate (savedInstanceState );

This. getWindow (). setFlags (WindowManager. LayoutParams. FLAG_FULLSCREEN, WindowManager. LayoutParams. FLAG_FULLSCREEN );

// Hide icons such as battery and all modifiers (status bar)

This. requestWindowFeature (Window. FEATURE_NO_TITLE );

// Hide the title bar (program name)

SetContentView (new MyView (this ));

}

}

Note: hiding the title (Application name) This setting must be written before setContentView; otherwise, an exception may occur!

For full screen setting, there are two main points:

The first point is to set the hidden status bar, including the battery icon, and the second point is to hide the name of our application, so that the full screen is displayed.

Package com. himi;

Import android. content. Context;

Import android. graphics. Canvas;

Import android. graphics. Color;

Import android. graphics. Paint;

Import android. graphics. Rect;

Import android. graphics. RectF;

Import android. view. View;

Public class MyView extends View {

Private Paint paint;

Public MyView (Context context ){

Super (context );

Paint = new Paint ();

Paint. setAntiAlias (true); // set the paint brush to be non-sawtooth (if not set, the effect is poor)

This. setKeepScreenOn (true); // set the background to always bright.

Paint. setColor (Color. RED );

}

@ Override

Public void onDraw (Canvas canvas ){

Canvas. drawColor (Color. WHITE); // you can specify the screen Color.

Rect rect = new Rect (30, 30, 50, 50); // The last two parameters here are not the width and height, but the coordinates at the bottom right corner of the rectangle.

Canvas. drawRect (rect, paint );

RectF rectF = new RectF (70f, 30f, 90f, 90f)

Canvas. drawArc (rectF, 0,360, true, paint );

Canvas. drawCircle (150, 30, 20, paint); // This is the third parameter of the circle as the radius.

Float [] points = new float [] {200f, 10f, 200f, 40f, 300f, 30f, 400f, 70f };

Canvas. drawLines (points, paint );

// Canvas. drawLines (points, 1, 4, paint); // select two points in the array of specific points to draw a straight line

Canvas. drawText ("Himi", 230, 30, paint );

}

}

You can also define the portrait screen in AndroidManifest. xml:

Android: theme = "@ android: style/Theme. NoTitleBar" hide the title bar

Android: theme = "@ android: style/Theme. NoTitleBar. Fullscreen" hide the status bar

 

 

This article is from the "Himi" blog, please be sure to keep this source http://xiaominghimi.blog.51cto.com/2614927/605693

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.