Android function guide interface implementation, android Interface

Source: Internet
Author: User

Android function guide interface implementation, android Interface

I. Interface implementation:

Learning from others' instances and recording the implementation of the guiding interface is not difficult in general. The premise is that you have an artist to help you with these guiding pictures (find a picture to make it work together):


Main Interface:

Public class MainActivity extends PromptActivity {// life cycle of the activity public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); setGuideResId (R. drawable. prompt2); // Add boot page }}

Guide interface:

Public class PromptActivity extends Activity {private int guideResourceId = 0; // boot page image resource idprivate PromptSharedPreferences psp; @ Overrideprotected void onStart () {super. onStart (); addGuideImage (); // Add boot page} // display the Boot Image public void addGuideImage () {psp = new PromptSharedPreferences (); View view = getWindow (). getDecorView (). findViewById (R. id. my_content_view); // find the root layout on setContentView if (view = null) return; if (Psp. takeSharedPreferences (this) {// jump out of the return;} ViewParent viewParent = view. getParent (); if (viewParent instanceof FrameLayout) {final FrameLayout frameLayout = (FrameLayout) viewParent; if (guideResourceId! = 0) {// set the 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) {// Delete the pilot image frameLayout. removeView (guideImage); // Save the psp record. saveSharedPreferences (PromptActivity. this, "started") ;}}); frameLayout. addView (guideImage); // Add a guiding image }}// obtain the image idprotected void setGuideResId (int resId) {this. guideResourceId = resId ;}}

Layout:

<? 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 = "hahahahaha"/> <TextView android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: layout_marginTop = "58dp" android: layout_marginLeft = "275dp" android: text = "ha"/> </RelativeLayout>

Local file:

Public class PromptSharedPreferences {private SharedPreferences sp; // save public void saveSharedPreferences (Context context, String save) {sp = context. getSharedPreferences ("prompt", context. MODE_PRIVATE); Editor editor = sp. edit (); editor. putString ("state", save); editor. commit (); // save New Data} // retrieve 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 ;}}}

Add values/ids. xml:

<?xml version="1.0" encoding="utf-8"?><resources><item type="id" name="my_content_view"></item></resources>


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.