android 功能引導介面實現

來源:互聯網
上載者:User

標籤:android

一.介面實現:

      借鑒了別人的執行個體,然後記錄下引導介面的實現,總體來說實現不算困難,前提是要有個美工幫你做這些引導圖片(找了張圖片湊合用吧):


   主介面:

public class MainActivity extends PromptActivity {    //activity的生命週期public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);setGuideResId(R.drawable.prompt2);// 添加引導頁}}

引導介面:

public class PromptActivity extends Activity {private int guideResourceId = 0;// 引導頁圖片資源idprivate PromptSharedPreferences psp;@Overrideprotected void onStart() {super.onStart();addGuideImage();// 添加引導頁}//顯示引導圖片public void addGuideImage() {psp = new PromptSharedPreferences();View view = getWindow().getDecorView().findViewById(R.id.my_content_view);// 尋找通過setContentView上的根布局if (view == null)return;if (psp.takeSharedPreferences(this)) {// 有過功能引導,就跳出return;}ViewParent viewParent = view.getParent();if (viewParent instanceof FrameLayout) {final FrameLayout frameLayout = (FrameLayout) viewParent;if (guideResourceId != 0) {// 設定了引導圖片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) {//刪除引導圖片frameLayout.removeView(guideImage);//儲存記錄psp.saveSharedPreferences(PromptActivity.this, "啟動了");}});frameLayout.addView(guideImage);// 添加引導圖片}}}//獲得圖片idprotected void setGuideResId(int resId) {this.guideResourceId = resId;}}

布局:

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

本地檔案:

public class PromptSharedPreferences {private SharedPreferences sp;// 儲存public void saveSharedPreferences(Context context, String save) {sp = context.getSharedPreferences("prompt", context.MODE_PRIVATE);Editor editor = sp.edit();editor.putString("state", save);editor.commit();// 儲存新資料}// 取出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;}}}

添加values/ids.xml:

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


    

android 功能引導介面實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.