ShowcaseView,一个快速简单的用户指引库.

来源:互联网 发布:excel数据库功能 编辑:程序博客网 时间:2024/05/29 17:13

ShowcaseView

ShowcaseView 是一个非常适合用于对用户进行第一次使用进行指导的库,使用起来非常简单还可以自定义样式

网址 : https://github.com/amlcurran/ShowcaseView

1.添加依赖

compile 'com.github.amlcurran.showcaseview:library:版本号'

2.使用

    //以下的参数lps用于设置按钮的位置    RelativeLayout.LayoutParams lps = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);    lps.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);    lps.addRule(RelativeLayout.ALIGN_PARENT_LEFT);    int margin = ((Number) (getResources().getDisplayMetrics().density * 12)).intValue();    lps.setMargins(margin, margin, margin, margin);    Target viewTarget = new ViewTarget(R.id.rb4, this);     //R.id.rb4指定的要突出显示的控件的id    sv = new ShowcaseView.Builder(this)            .withMaterialShowcase()            .setStyle(R.style.CustomShowcaseTheme)  //设置自定义样式            .setTarget(viewTarget)            .setContentTitle("提示")      //标题的文字            .setContentText("我从来没有遇到过这样的傻逼")        //提示的内容            .hideOnTouchOutside()   //点击空白位置也会被隐藏               .singleShot(49654546)       //用于单次显示. 当下次发现这个int值所标示的已经显示过了,就不再显示.int值自己随便写,注意不要重复就好            .build();    sv.setButtonPosition(lps);

注意事项

导包的问题:        import com.github.amlcurran.showcaseview.ShowcaseView;        import com.github.amlcurran.showcaseview.targets.ViewTarget;        import com.github.amlcurran.showcaseview.targets.Target;//这个as的自动导包功能可能会导错包

自定义样式

#aced680f //整个大背景的颜色
#ed680f //按钮的背景颜色
确定 //按钮上的文字
@style/CustomTitle //标题的字体样式
@style/CustomText //提示内容的字体样式

<style name="CustomTitle" parent="TextAppearance.ShowcaseView.Title.Light">    <item name="android:textColor">#deffffff</item></style><style name="CustomText" parent="TextAppearance.ShowcaseView.Detail.Light">    <item name="android:textColor">#8affffff</item></style>

3.效果

图中的文字用来吐槽产品一直改需求,请各位忽略(捂脸)