成都网站建设设计

将想法与焦点和您一起共享

android引导页,android启动页广告页

android应用更新后,怎么重新进入引导页

一般有两个方法:

公司主营业务:成都做网站、网站设计、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。成都创新互联是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。成都创新互联推出淇滨免费做网站回馈大家。

1、切换账号登录,引导页可以重新查看;

2、在手机“设置”的“应用”中,点击相应的应用后,点击“清除数据”。这样的话就得重新登录了。

第二种方法彻底,但某些应用谨慎使用,因为可能有的应用之前保存的数据就没了,除非这款应用可以同步相关数据。

考虑上面的情况,你也可以用第一种方法,切换后再切换回来。当然,我一般用第二种方法,快...

android studio怎么设置引导页

 基本上现在所有的应用都会有一个欢迎界面,在欢迎界面对应用做一个整体的介绍,然后在跳入到主界面,这次要说的这个引导页就是带翻页的引导页。效果如下所示

概要实现

主要分为两部分功能,一个是翻页效果,一个是页面位置指示器。为了实现翻页效果我采用系统自带的ViewPager对象来实现;页面指示器则通过一个LinearLayout在其中放置相应个数的图片,然后根据页面的滑动动态修改各个图片的资源。布局文件如下所示

复制代码

1 RelativeLayout xmlns:android=""

2 xmlns:tools=""

3 android:layout_width="match_parent"

4 android:layout_height="match_parent"

5 tools:context=".MainActivity"

6

7 android.support.v4.view.ViewPager

8 xmlns:android=""

9 android:id="@+id/welcome_pager"

10 android:layout_width="match_parent"

11 android:layout_height="match_parent" /

12

13 !-- 图片位置指示器 --

14 LinearLayout

15 android:id="@+id/director"

16 android:layout_width="match_parent"

17 android:layout_height="wrap_content"

18 android:gravity="center_horizontal"

19 android:orientation="horizontal"

20 android:layout_marginBottom="15dip"

21 android:layout_alignParentBottom="true"

22

23

24 ImageView

25 android:layout_width="wrap_content"

26 android:layout_height="wrap_content"

27 android:background="@drawable/pageindicator_on" /

28

29 ImageView

30 android:layout_width="wrap_content"

31 android:layout_height="wrap_content"

32 android:background="@drawable/pageindicator_off" /

33

34 ImageView

35 android:layout_width="wrap_content"

36 android:layout_height="wrap_content"

37 android:background="@drawable/pageindicator_off" /

38

39 ImageView

40 android:layout_width="wrap_content"

41 android:layout_height="wrap_content"

42 android:background="@drawable/pageindicator_off" /

43 /LinearLayout

44

45 /RelativeLayout

复制代码

ViewPager

先来看下官方解释:Layout manager that allows the user to flip left and right through pages of data.意思是说,Viewpage是一个允许用户在多个页面数据之间通过左滑或者右滑的方式切换页面数据的布局管理器。

主要功能点有两部分,数据适配器Adapter,和事件监听器OnPageChangeListener。数据适配器用来管理这个ViewPager对象的显示内容,而OnPageChangeListener用来处理当页面切换的时候的行为动作,我修改页面指示器就是通过这个事件来完成的。

适配器

复制代码

1 class pagerAdapter extends FragmentPagerAdapter{

2

3 public pagerAdapter(FragmentManager fm) {

4 super(fm);

5 }

6

7 @Override

8 public Fragment getItem(int arg0) {

9 //得到要显示的对象并初始化图片

10 WelcomeFragment fm = new WelcomeFragment();

11 fm.setImg(imgs.get(arg0));

12

13 return fm;

14 }

15

16 @Override

17 public int getCount() {

18 return imgs.size();

19 }

20

21 }

复制代码

上面这段就是ViewPager要用的适配器了,其中imgs是一个id数组,存放了要在欢迎界面展示的图片的id,WelcomeFragment是一个Fragment类,用来展示页面内容,这两个代码会在完整代码中体现。两个方法需要实现,getCout,用来表示有多少个页面;getItem,用来获取指定位置的Pager对象。

imgs数组定义及实现:

复制代码

1 ListInteger imgs = null;

2 //初始化欢迎界面图片数组

3 imgs = new ArrayListInteger();

4 imgs.add(R.drawable.help1);

5 imgs.add(R.drawable.help2);

6 imgs.add(R.drawable.help3);

7 imgs.add(R.drawable.help4);

复制代码

WelcomeFragment类定义

复制代码

1 public class WelcomeFragment extends Fragment {

2

3 View view = null;

4 int imgId ;

5 @Override

6 public View onCreateView(LayoutInflater inflater, ViewGroup container,

7 Bundle savedInstanceState) {

8 view = inflater.inflate(R.layout.welcome_fragment, null);

9

10 ImageView fragmentVw = (ImageView) view.findViewById(R.id.welcome_Img);

11 fragmentVw.setBackgroundResource(imgId);

12 return view;

13 }

14

15 /**

16 * 为该Fragment设置显示图片

17 * */

18 public void setImg(int imgID){

19

20 imgId = imgID;

21 }

22 }

复制代码

WelcomeFragment布局文件

复制代码

1 FrameLayout xmlns:android=""

2 android:layout_width="match_parent"

3 android:layout_height="match_parent"

4

5 ImageView

6 android:id="@+id/welcome_Img"

7 android:contentDescription="welcome"

8 android:layout_width="match_parent"

9 android:layout_height="match_parent" /

10

11 /FrameLayout

复制代码

事件监听器OnPageChangeListener

这个监听器用来监听页面切换事件,实现这个接口用来处理页面切换时,页面指示器跟着改变状态。实现代码如下

复制代码

1 /**

2 * 页面切换的事件监听器

3 * */

4 class pageChangeListener implements OnPageChangeListener{

5

6 /**

7 * 当某一个页面被选中的时候触发

8 * */

9 @Override

10 public void onPageSelected(int arg0) {

11 int count = directorLayout.getChildCount();

12 /**

13 * 指示器自对象顺序和页面显示顺序一样的设置为on,其余的设置为off

14 * */

15 for(int i=0;icount;i++){

16 ImageView iv = (ImageView) directorLayout.getChildAt(i);

17 if(i == arg0){

18 iv.setBackgroundResource(R.drawable.pageindicator_on);

19 }else{

20 iv.setBackgroundResource(R.drawable.pageindicator_off);

21 }

22 }

23 }

24

25 @Override

26 public void onPageScrolled(int arg0, float arg1, int arg2) {

27 // TODO Auto-generated method stub

28 }

29

30 @Override

31 public void onPageScrollStateChanged(int arg0) {

32 // TODO Auto-generated method stub

33 }

34 }

android怎么从引导页进入主页

1 import android.app.Activity;

2 import android.content.Intent;

3 import android.content.SharedPreferences;

4 import android.content.SharedPreferences.Editor;

5 import android.os.Bundle;

6 import android.os.Handler;

7

8 /** 欢迎界面 */

9 public class WelcomeAct extends Activity {

10

11 private boolean isFirstIn = false;

12 private static final int TIME = 2000;

13 private static final int GO_HOME = 1000;

14 private static final int GO_GUIDE = 1001;

15

16 private Handler mHandler = new Handler() {

17 public void handleMessage(android.os.Message msg) {

18 switch (msg.what) {

19 // 跳入主界面

20 case GO_HOME:

21 goHome();

22 break;

23 // 跳入引导页

24 case GO_GUIDE:

25 goGuide();

26 break;

27 }

28 };

29 };

30

31 @Override

32 protected void onCreate(Bundle savedInstanceState) {

33 super.onCreate(savedInstanceState);

34 setContentView(R.layout.welcome);

35 init();

36 }

37

38 private void init() {

39 SharedPreferences perPreferences = getSharedPreferences("jike",

40 MODE_PRIVATE);

41 isFirstIn = perPreferences.getBoolean("isFirstIn", true);

42 if (!isFirstIn) {

43 mHandler.sendEmptyMessageDelayed(GO_HOME, TIME);

44 } else {

45 mHandler.sendEmptyMessageDelayed(GO_GUIDE, TIME);

46 Editor editor = perPreferences.edit();

47 editor.putBoolean("isFirstIn", false);

48 editor.commit();

49 }

50 }

51

52 private void goHome() {

53 Intent i = new Intent(WelcomeAct.this, MainActivity.class);

54 startActivity(i);

55 finish();

56 }

57

58 private void goGuide() {

59 Intent i = new Intent(WelcomeAct.this, Guide.class);

60 startActivity(i);

61 finish();

62 }

63

64 }

1 import java.util.ArrayList;

2 import java.util.List;

3 import android.app.Activity;

4 import android.content.Intent;

5 import android.os.Bundle;

6 import android.support.v4.view.ViewPager;

7 import android.support.v4.view.ViewPager.OnPageChangeListener;

8 import android.view.LayoutInflater;

9 import android.view.View;

10 import android.view.View.OnClickListener;

11 import android.widget.Button;

12 import android.widget.ImageView;

13

14 /** 引导页 */

15 public class Guide extends Activity implements OnPageChangeListener {

16

17 private ViewPager vp;

18 private ViewPagerAdapter vpAdapter;

19 private ListView views;

20 private ImageView[] dots;

21 private int[] ids = { R.id.iv1, R.id.iv2, R.id.iv3 };

22 private Button start_btn;

23

24 @Override

25 protected void onCreate(Bundle savedInstanceState) {

26 super.onCreate(savedInstanceState);

27 setContentView(R.layout.guide);

28 initViews();

29 initDots();

30 }

31

32 private void initViews() {

33 LayoutInflater inflater = LayoutInflater.from(this);

34

35 views = new ArrayListView();

36 views.add(inflater.inflate(R.layout.one, null));

37 views.add(inflater.inflate(R.layout.two, null));

38 views.add(inflater.inflate(R.layout.three, null));

39

40 vpAdapter = new ViewPagerAdapter(views, this);

41 vp = (ViewPager) findViewById(R.id.viewpager);

42 vp.setAdapter(vpAdapter);

43 // 下标从0开始,所以第三个页面是get(2)。

44 start_btn = (Button) views.get(2).findViewById(R.id.start_btn);

45 start_btn.setOnClickListener(new OnClickListener() {

46 @Override

47 public void onClick(View arg0) {

48 Intent i = new Intent(Guide.this, MainActivity.class);

49 startActivity(i);

50 finish();

51 }

52 });

53 vp.setOnPageChangeListener(this);

54 }

55

56 /** 循环设置点 */

57 private void initDots() {

58 dots = new ImageView[views.size()];

59 for (int i = 0; i views.size(); i++) {

60 dots[i] = (ImageView) findViewById(ids[i]);

61 }

62 }

63

64 @Override /** 滑动状态改变的时候 */

65 public void onPageScrollStateChanged(int arg0) {

66 // TODO Auto-generated method stub

67 }

68

69 @Override /** 当页面被滑动时候调用 */

70 public void onPageScrolled(int arg0, float arg1, int arg2) {

71 // TODO Auto-generated method stub

72 }

73

74 @Override /** 当前新的页面被选中时调用 */

75 public void onPageSelected(int arg0) {

76 for (int i = 0; i ids.length; i++) {

77 if (arg0 == i) {

78 // 亮点

79 dots[i].setImageResource(R.drawable.login_point_selected);

80 } else {

81 // 暗点

82 dots[i].setImageResource(R.drawable.login_point);

83 }

84 }

85 }

86

87 }

1 ?xml version="1.0" encoding="utf-8"?

2 RelativeLayout xmlns:android=""

3 android:layout_width="match_parent"

4 android:layout_height="match_parent"

5

6 android.support.v4.view.ViewPager

7 android:id="@+id/viewpager"

8 android:layout_width="fill_parent"

9 android:layout_height="fill_parent"

10 android:background="#00000000"

11 /android.support.v4.view.ViewPager

12

13 !-- 底部三个点 --

14 LinearLayout

15 android:id="@+id/ll"

16 android:layout_width="fill_parent"

17 android:layout_height="wrap_content"

18 android:layout_alignParentBottom="true"

19 android:gravity="center_horizontal"

20 android:orientation="horizontal"

21 !-- 选中点 --

22 ImageView

23 android:id="@+id/iv1"

24 android:layout_width="wrap_content"

25 android:layout_height="wrap_content"

26 android:src="@drawable/login_point_selected" /

27 !-- 未选中点 --

28 ImageView

29 android:id="@+id/iv2"

30 android:layout_width="wrap_content"

31 android:layout_height="wrap_content"

32 android:src="@drawable/login_point" /

33 !-- 未选中点 --

34 ImageView

35 android:id="@+id/iv3"

36 android:layout_width="wrap_content"

37 android:layout_height="wrap_content"

38 android:src="@drawable/login_point" /

39 /LinearLayout

40

41 /RelativeLayout

Android初探开机引导

因为需求有做开机引导,所以简单的学习下这块功能的流程,并简单的做个总结

主要参考文章:

做开机引导,主要要做到的效果就是 只有第一次使用的时候会打开,只打开一次,当执行完开机引导的流程之后,之后开机都不会再展示

要实现开机引导,那么就一定是系统应用,按照原理来说,需要两个步骤,第一,需要引导页的优先级比LAUNCHER高。第二,需要流程完毕之后执行某些操作让应用下次不会启动。

可以设置android:priority属性,系统会判断启动priority优先级高的。

这样配置之后,其它应用的优先级如果没有设置的话默认就是0,这样就会优先打开引导页。

自己可以在引导页中写自己想要做的逻辑。当执行完所有逻辑之后,需要配置

这里主要做了设置Settings.Global.DEVICE_PROVISIONED和Settings.Secure.USER_SETUP_COMPLETE两个参数,还有PackageManager.setComponentEnabledSetting方法禁用组件

第一个参数是组件名

第二个参数是状态

不可用状态:COMPONENT_ENABLED_STATE_DISABLED

可用状态:COMPONENT_ENABLED_STATE_ENABLED

默认状态:COMPONENT_ENABLED_STATE_DEFAULT

第三个参数flags

DONT_KILL_APP或者0,0表示杀死包含该组件的app

运行时会发现设置priority优先级比LAUNCHER高,在开机之后也会提示让你选择打开应用,而不是默认打开优先级高的,关于这个问题,可以参考这篇文章

只需要把应用安装到system/priv-app中,就能解决这个问题。正常来说一般系统应用也是安装在这么文件夹中,只是平时调试的时候会为了方便直接run,所以可能出现这个问题。

将应用安装到该文件夹中可以使用这个命令,然后重启

看了很多文章,都没有讲到为什么要设置这两属性,因为要达成目的,我们只需要设置priority和调用setComponentEnabledSetting方法就行,为什么要设置这两个参数?不设置会有什么影响。

其实简单来说,系统在其他地方有用到这两个参数,举个简单的例子,我直接

去运行程序,能够很明显的测出这种情况下按Home键没反应,除此之外屏保也会不显示。

所以这两个参数还是需要在这个地方设为1的。


本文名称:android引导页,android启动页广告页
新闻来源:http://chengdu.cdxwcx.cn/article/dsdehio.html