Android功能引导页的实现
来源:互联网 发布:淘宝心级怎么算买家 编辑:程序博客网 时间:2024/04/30 13:48
一.界面实现:
借鉴了别人的实例,然后记录下引导界面的实现,总体来说实现不算困难,前提是要有个美工帮你做这些引导图片(找了张图片凑合用吧):
主界面:
public class MainActivity extends PromptActivity { //activity的生命周期public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);setGuideResId(R.drawable.prompt2);// 添加引导页}}
引导界面:
public class PromptActivity extends Activity {private int guideResourceId = 0;// 引导页图片资源idprivate PromptSharedPreferences psp;@Overrideprotected void onStart() {super.onStart();addGuideImage();// 添加引导页}//显示引导图片public void addGuideImage() {psp = new PromptSharedPreferences();View view = getWindow().getDecorView().findViewById(R.id.my_content_view);// 查找通过setContentView上的根布局if (view == null)return;if (psp.takeSharedPreferences(this)) {// 有过功能引导,就跳出return;}ViewParent viewParent = view.getParent();if (viewParent instanceof FrameLayout) {final FrameLayout frameLayout = (FrameLayout) viewParent;if (guideResourceId != 0) {// 设置了引导图片final ImageView guideImage = new ImageView(this);FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT);guideImage.setLayoutParams(params);guideImage.setScaleType(ScaleType.FIT_XY);guideImage.setImageResource(guideResourceId);guideImage.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//删除引导图片frameLayout.removeView(guideImage);//保存记录psp.saveSharedPreferences(PromptActivity.this, "启动了");}});frameLayout.addView(guideImage);// 添加引导图片}}}//获得图片idprotected void setGuideResId(int resId) {this.guideResourceId = resId;}}
布局:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@id/my_content_view" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="58dp" android:layout_marginLeft="150dp" android:text="哈哈哈哈" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="58dp" android:layout_marginLeft="275dp" android:text="哈" /></RelativeLayout>
本地文件:
public class PromptSharedPreferences {private SharedPreferences sp;// 保存public void saveSharedPreferences(Context context, String save) {sp = context.getSharedPreferences("prompt", context.MODE_PRIVATE);Editor editor = sp.edit();editor.putString("state", save);editor.commit();// 保存新数据}// 取出public boolean takeSharedPreferences(Context context) {String str = "";sp = context.getSharedPreferences("prompt", context.MODE_PRIVATE);str = sp.getString("state", "");if (str.equals("")) {return false;}else{ return true;}}}
添加values/ids.xml:
<?xml version="1.0" encoding="utf-8"?><resources><item type="id" name="my_content_view"></item></resources>
0 0
- Android功能引导页的实现
- Android 实现闪屏页+功能引导页
- 【Android】如何实现启动APP时引导页、欢迎页功能之(一)引导页功能的实现
- Android 引导页功能
- android引导页的实现
- Android 引导页的实现
- Android引导页的实现
- unity3d for Android实现欢迎引导页面的功能
- android(2) 功能引导界面实现
- android实现App新手引导功能
- Android ViewPager程序引导页的实现
- android引导页的实现办法
- android-引导页的实现方式
- Android的功能引导、新功能介绍、ViewFlipper
- android 引导界面的实现
- android 引导界面的实现 .
- Android引导界面的实现 .
- Android引导页面的实现
- 本地缓存
- rc/dc 工具报错的解决方案
- Java折半查找法代码
- PHP7 编译自带的扩展库
- NavigationController和scrollView的问题
- Android功能引导页的实现
- 算法---分类算法之贝叶斯分类
- GitHub for Windows 2.0使用教程
- eclispe工程没有编译的解决办法
- 深度学习-网络Xavier初始化方法
- git代码统计-生成详细html报告
- Metal Performance Shader使用小结
- jQuery和jquerymobile 实现火车票查询
- 异常:IllegalStateException: The application's PagerAdapter changed the adapter's contents