Insert boot page in the specified interface in Android

Source: Internet
Author: User

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 ();
}

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.