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