binbinyang---Android 应用第一次运行时,引导页面的设置方法(只让程序Acitivity运行一次的设置方法)+SharedPreferences

在开发中..不管你做什么类型的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里面核心代码:

@Override
	protected 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_APPEND
Context.MODE_APPEND:模式会检查文件是否存在,存在就往文件追加内容,否则就创建新文件。
Context.MODE_WORLD_READABLE和Context.MODE_WORLD_WRITEABLE用来控制其他应用是否有权限读写该文件。
MODE_WORLD_READABLE:表示当前文件可以被其他应用读取;
MODE_WORLD_WRITEABLE:表示当前文件可以被其他应用写入。

最后放上 我录取的 动态效果图 




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值