binbinyang---Android 应用第一次运行时,引导页面的设置方法(只让程序Acitivity运行一次的设置方法)+SharedPreferences
来源:互联网 发布:面试软件项目介绍 编辑:程序博客网 时间:2024/05/18 23:55
在开发中..不管你做什么类型的APP.为了给用户一种舒服的用户体验,都应该有一个引导界面,.我在这么久的开发中.也写过很多引导界面,于是我就想把这个写成一个文章,方便大家学习交流...一下是我今天开发遇到的引导界面
先上效果图
首先 在布局上...我在这个界面的布局 总布局立面是一个
代码部分:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <include android:id="@+id/bar" android:layout_width="match_parent" android:layout_height="@dimen/component_height_larger" layout="@layout/main_action_bar" /> <LinearLayout android:id="@+id/buttom_bar" android:layout_width="match_parent" android:layout_height="@dimen/component_height_middle" android:layout_alignParentBottom="true" android:weightSum="5" android:background="@drawable/bottom_bg" > <include layout="@layout/bottom_navigation_homepage" /> <include layout="@layout/bottom_navigation_record" /> <include layout="@layout/bottom_navigation_empty" /> <include layout="@layout/bottom_navigation_manage" /> <include layout="@layout/bottom_navigation_my" /> </LinearLayout> <FrameLayout android:id="@+id/content" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_above="@+id/buttom_bar" android:layout_alignParentLeft="true" android:layout_below="@+id/bar" android:background="@color/background_gray" > </FrameLayout> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:paddingBottom="@dimen/height_deliver_lines" android:src="@drawable/index_channel" /> <FrameLayout android:id="@+id/fryout1" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone" android:background="#88000000" > <View android:background="@drawable/page1" android:layout_width="match_parent" android:layout_height="match_parent"/> </FrameLayout> <FrameLayout android:id="@+id/fryout2" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone" android:background="#88000000" > <View android:background="@drawable/page2" android:layout_width="match_parent" android:layout_height="match_parent"/> </FrameLayout> </RelativeLayout>
我吧引导图 有2个 放在
FrameLayout里面
Activity里面核心代码:
@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.activity_main);preferences = getSharedPreferences("count",Context.MODE_PRIVATE); int count = preferences.getInt("count", 0); System.out.println(count+"countcountcountcountcountcountcountcount"); //判断程序与第几次运行,如果是第一次运行则跳转到引导页面 fr1 = (FrameLayout) findViewById(R.id.fryout1); fr2 = (FrameLayout) findViewById(R.id.fryout2); if (count == 0) { fr1.setVisibility(View.VISIBLE); fr1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { fr1.setVisibility(View.GONE); fr2.setVisibility(View.VISIBLE); } }); fr2.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { fr2.setVisibility(View.GONE); fr1.setVisibility(View.GONE); } }); } else { fr2.setVisibility(View.GONE);fr1.setVisibility(View.GONE);} Editor editor = preferences.edit(); //存入数据 editor.putInt("count", ++count); //提交修改 editor.commit();
同时我想说一下
Context.MODE_PRIVATE:为默认操作模式,代表该文件是私有数据,只能被应用本身访问,在该模式下,写入的内容会覆盖原文件的内容,如果想把新写入的内容追加到原文件中。可以使用Context.MODE_APPENDContext.MODE_APPEND:模式会检查文件是否存在,存在就往文件追加内容,否则就创建新文件。Context.MODE_WORLD_READABLE和Context.MODE_WORLD_WRITEABLE用来控制其他应用是否有权限读写该文件。MODE_WORLD_READABLE:表示当前文件可以被其他应用读取;MODE_WORLD_WRITEABLE:表示当前文件可以被其他应用写入。
最后放上 我录取的 动态效果图
0 0
- binbinyang---Android 应用第一次运行时,引导页面的设置方法(只让程序Acitivity运行一次的设置方法)+SharedPreferences
- Android 应用第一次运行时,引导页面的设置方法(只让程序Acitivity运行一次的设置方法)
- Android 应用第一次运行时,引导页面的设置方法(只让程序Acitivity运行一次的设置方法)
- Android 应用第一次运行时,引导页面的设置方法(只让程序Acitivity运行一次的设置方法)
- Android 应用第一次运行时,引导页面的设置方法(只让程序Acitivity运行一次的设置方法)
- Android 应用第一次运行时,引导页面的设置方法(只让程序Acitivity运行一次的设置方法)
- Android 应用第一次运行时,引导页面的设置方法(只让程序Acitivity运行一次的设置方法)
- Delphi中,让程序只运行一次的方法
- 程序只运行一次的方法
- android 第一次运行应用的引导界面
- android 第一次运行应用的引导界面
- c# 程序只运行一次的处理方法
- android只让某个activity运行一次-SharedPreferences
- 让程序只运行一个实例的方法
- 让程序只运行一个实例的方法总结[转]
- 让程序只运行一个实例的方法总结
- 让程序只运行一个实例的四种方法
- VC让程序只运行一个实例的方法
- 要将pdf转换成txt格式的文件怎么转
- item
- C# using用法详解
- 《深入理解计算机系统》思考1---系统调用相关
- adb push 遇到 "Read-only file system" 無法寫入的問題
- binbinyang---Android 应用第一次运行时,引导页面的设置方法(只让程序Acitivity运行一次的设置方法)+SharedPreferences
- 123123
- 手机APP自动化测试简单录制
- 用 java 写一个计算器
- java.util.concurrent 学习笔记(1)
- 777777777
- 用HIBERNATE实现领域对象的自定义字段
- ubuntu下安装新立得(Synaptic)出现安装错误的解决尝试
- [思路题] hdu 5414 CRB and String