android first screen and one to the guide interface

It is very necessary for the design of the first screen and the guide interface during the android development process

The first screen: the first interface that the app starts, just like qq and WeChat



Guide interface: It tells you the function of the application when it is opened for the first time. It is usually composed of several pictures. After opening it for the first time, it will not appear as shown below:

        


Difficulty: The first screen is turned off after opening for 2~3 seconds (actually it is an Activity). When opening the app, it is judged whether it is opened for the first time to determine whether the guide interface should be called. The guide interface can be slid (actually) The above is the combination of viewpager and fragment)

On the code:

package com.qrnu.ly.mi;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;

import com.qrnu.ly.R;
import com.qrnu.ly.guild.GuideActivity;

/**
 * android android第一屏和引导界面
 * 
 * @author
 * 
 */
public class FirstActivity extends Activity {
	private SharedPreferences preferences;
	private Editor editor;
	private final int SPLASH_DISPLAY_LENGHT = 3000;//开启之后停顿3秒

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.first);

		preferences = getSharedPreferences("guide", Context.MODE_PRIVATE);

		new Handler().postDelayed(new Runnable() {
			@Override
			public void run() {
				if (preferences.getBoolean("FirstActivity", true)) {
					editor = preferences.edit();
					editor.putBoolean("FirstActivity", false);
					editor.commit();
					Intent intent = new Intent();
					intent.setClass(FirstActivity.this, GuideActivity.class);
					startActivity(intent);
					finish();
				} else {

					Intent intent = new Intent();
					intent.setClass(FirstActivity.this, MainActivity.class);
					startActivity(intent);
					finish();
				}

			}

		}, SPLASH_DISPLAY_LENGHT);
	}
}

GuideActivity.class 调用引导界面
 MainActivity.class进入主界面

GuideActivity code

package com.qrnu.ly.guild;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.Window;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.qrnu.ly.R;

public class GuideActivity extends FragmentActivity {

	private ViewPager viewPage;
	private Fragment1 mFragment1;
	private Fragment2 mFragment2;
//	private Fragment3 mFragment3;
	private Fragment4 mFragment4;
	private PagerAdapter mPgAdapter;
	private RadioGroup dotLayout;
	private List<Fragment> mListFragment = new ArrayList<Fragment>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题栏
		setContentView(R.layout.activity_guide);
		initView();
		viewPage.setOnPageChangeListener(new MyPagerChangeListener());

	}

	private void initView() {
		dotLayout = (RadioGroup) findViewById(R.id.advertise_point_group);
		viewPage = (ViewPager) findViewById(R.id.viewpager);
		mFragment1 = new Fragment1();
		mFragment2 = new Fragment2();
//		mFragment3 = new Fragment3();
		mFragment4 = new Fragment4();
		mListFragment.add(mFragment1);
		mListFragment.add(mFragment2);
//		mListFragment.add(mFragment3);
		mListFragment.add(mFragment4);
		mPgAdapter = new ViewPagerAdapter(getSupportFragmentManager(),
				mListFragment);
		viewPage.setAdapter(mPgAdapter);

	}

	public class MyPagerChangeListener implements OnPageChangeListener {

		public void onPageSelected(int position) {

		}

		public void onPageScrollStateChanged(int arg0) {

		}

		public void onPageScrolled(int position, float positionOffset,
				int positionOffsetPixels) {
			((RadioButton) dotLayout.getChildAt(position)).setChecked(true);
		}

	}
}

Fragment1 Fragment2 Fragment4 is used in it 

Fragment1 code

package com.qrnu.ly.guild;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.qrnu.ly.R;

public class Fragment1 extends Fragment {

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		super.onCreateView(inflater, container, savedInstanceState);
		return inflater.inflate(R.layout.guide_1, container, false);
	}

}
Fragment2 code

package com.qrnu.ly.guild;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.qrnu.ly.R;

public class Fragment2 extends Fragment{
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		super.onCreateView(inflater, container, savedInstanceState);
		return inflater.inflate(R.layout.guide_2, container, false);
	}
	
}


Fragment4 code

package com.qrnu.ly.guild;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.qrnu.ly.R;
import com.qrnu.ly.mi.MainActivity;

public class Fragment4 extends Fragment {

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		super.onCreateView(inflater, container, savedInstanceState);
		return inflater.inflate(R.layout.guide_4, container, false);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);

		TextView textView = (TextView) getView().findViewById(R.id.tvInNew);

		textView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent();
				intent.setClass(getActivity(), MainActivity.class);
				startActivity(intent);
				getActivity().finish();
			}
		});
	}

}

In Fragment4, there is a Textview and click event to respond to the monitoring of entering the main interface (such as immediate experience) as shown below:


This blog may still have some incomprehensive aspects, I hope everyone can understand and will do better in the future.

If you don't like it, don't spray


Guess you like

Origin blog.csdn.net/u013521274/article/details/50651112