Here we mainly use the properties of windowmanager. layoutparams and the windowmanager. addvew (view, layoutparams Params) method.
Set the Params of the view on the boot page to be displayed, generate the guidepage object in the specified place, and call the showguidepage () method.
Public class guidepage {
Button mbutton;
Context mcontext;
Imageview mguideimage;
Windowmanager mwindowmanager;
Windowmanager. layoutparams mimageviewparams;
Windowmanager. layoutparams mbuttonparams;
/**
*
* @ Param Context
* @ Param windowmanager the windowmanager which will get the guidepage.
* @ Param resid the drawable resources ID for the guidepage to be shown.
* @ Param btntext the text that the button of the guidepage will show.
* @ Param btngravity the gravity attribute of the button, you can use gravity. Bottom or gravity. center_horizontal and so on for this Param.
* @ Return the guidepage instance to show.
*/
Public guidepage (context, windowmanager, int resid, string btntext, int btngravity ){
This. mcontext = context;
This. mbutton = new button (mcontext );
This. mbutton. settext (btntext );
This. mguideimage = new imageview (mcontext );
This. mguideimage. setimageresource (resid );
This. mguideimage. setscaletype (imageview. scaletype. fit_center );
This. mwindowmanager = windowmanager;
This. mimageviewparams = new layoutparams ();
This. mimageviewparams. Alpha = 0.5f;
This. mimageviewparams. width = layoutparams. match_parent;
This. mimageviewparams. Height = layoutparams. match_parent;
This. midmageviewparams. type = 2002;
This. mbuttonparams = new layoutparams (layoutparams. wrap_content, layoutparams. wrap_content, 2007,40, 1 );
This. mbuttonparams. Gravity = btngravity;
}
/**
* Show the guidepage instance.
*/
Public void showgudiepage (){
Mwindowmanager. addview (mbutton, mbuttonparams );
Mwindowmanager. addview (mguideimage, mimageviewparams );
Mbutton. setonclicklistener (New View. onclicklistener (){
@ Override
Public void onclick (view v ){
// Todo auto-generated method stub
Mwindowmanager. removeview (mbutton );
Mwindowmanager. removeviewimmediate (mguideimage );
}
});
}
}
// Use a method similar to the following to determine whether a program or a function is enabled for the first time
Void isfirstrun (){
Sharedpreferences sp = mcontext. getsharedpreferences ("pref_first_run", context. mode_private );
Boolean B = sp. getboolean ("isfirstrun", true );
If (B ){
New guidepage (mcontext, mwindowmanager, 0, null, 0). showgudiepage ();
Sp. Edit (). putboolean ("isfirstrun", false). Commit ();
}