android中在指定的界面中插入引导页
来源:互联网 发布:新手开淘宝网店 编辑:程序博客网 时间:2024/05/16 06:09
这里面主要用到的是WindowManager.LayoutParams的属性及windowManager.addVew(View view,LayoutParams params)的方法
将要显示的引导页的View的Params 设置好,在指定的地方生成guidepage的对像,并调用showGuidePage()方法即可。
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 context,WindowManager 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.mImageViewParams.type = 2002;
this.mButtonParams = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,2003,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);
}
});
}
}
//用类似下面的方法来判断程序或是某个功能是否是第一次启用
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();
}
- android中在指定的界面中插入引导页
- android中在指定的界面中插入引导页
- 【Android】每个Activity中加入引导界面
- Apicloud中引导界面
- Android中引导页
- ASP.NET 中在指定的位置处插入字符
- ASP.NET 中在指定的位置处插入字符
- ASP.NET 中在指定的位置处插入字符
- ASP.NET 中在指定的位置处插入字符
- 数据库中如何在指定的位置插入列
- 在PPT中播放插入flash的指定片段
- 在winform界面的菜单栏和工具栏中插入分界线
- 在iOS应用程序中打开设备设置界面及其中某指定的选项界面
- 在iOS应用程序中打开设备设置界面及其中某指定的选项界面
- 在iOS应用程序中打开设备设置界面及其中某指定的选项界面
- word中在指定位置插入图片
- 在一个字符串中插入指定字符
- 在datatable中,在指定位置插入列
- 运行Maven是报错:No goals have been specified for this build(转)
- DLL传递字符串数组输出参数
- 尝试加载 Oracle 客户端库时引发 BadImageFormatException。如果在安装 32 位 Oracle 客户端组件的情况下以 64 位模式运行,将出现此问题
- fedora 18 图文安装教程
- const的用法
- android中在指定的界面中插入引导页
- A. Triangle
- Flex开发ArcGIS问题集锦六:怎样使用空间引用
- C#下调用捷宝链接库函数整理
- 在jsp文件中调用自定义控件(如果不存在,自动下载CAB文件安装注册)
- PhoneGap API介绍:Connection
- 软件开发基本原则一------典型错误
- SQLServer sa登陆失败
- IO_缓冲和非缓冲