显示一种帮助“覆盖”

Rob*_*met 3 android

我想让我的应用程序对用户更加友好,所以我想在用户第一次启动应用程序时显示一种突出显示不同组件的叠加层。

开始实施的最佳方法是什么?

下面是一个例子:

在此处输入图片说明

Sob*_*obo 5

覆盖

我知道这很旧,但我发现了这个并做了一些轻微的修改。对我很有用。

创建并将您的“overlay.png”文件复制到“drawable”中

创建布局/overlay_activity.xml

<?xml version="1.0" encoding="utf-8"?>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/Overlay_activity"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background= "@null"
        android:orientation="vertical" >

    <ImageView
        android:id="@+id/ivOverlayEntertask"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/overlay" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

创建 xml/overlay_prefs.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

    <CheckBoxPreference
        android:defaultValue="true"
        android:key="overlaypref"
        android:summary="Enable Overlay Screen"
        android:title="Overlay Screen" />

</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)

在您的活动中,创建 SharedPreferences 和一个布尔值的实例来存储值:

SharedPreferences setOverlay;
boolean showOverlay;
Run Code Online (Sandbox Code Playgroud)

然后在 OnCreate 中获取叠加层 CheckBoxPreference 的值,如果为真,则将图像叠加到 Activity 上:

setOverlay = PreferenceManager.getDefaultSharedPreferences(this);
showOverlay = setOverlay.getBoolean("overlaypref", true);
    if (showOverlay == true) {
    showActivityOverlay();
    }
Run Code Online (Sandbox Code Playgroud)

Create a New Method in Activity: showActivityOverlay() What this Method does is, it shows the Overlay when the Activity starts and then when the user taps on the screen it will set the "overlaypref" to "false" and will no longer show the overlay.

  private void showActivityOverlay() {
      final Dialog dialog = new Dialog(this,
      android.R.style.Theme_Translucent_NoTitleBar);

      dialog.setContentView(R.layout.overlay_activity);

      LinearLayout layout = (LinearLayout) dialog
      .findViewById(R.id.overlay_activity);
      layout.setBackgroundColor(Color.TRANSPARENT);
        layout.setOnClickListener(new OnClickListener() {

          @Override
          public void onClick(View arg0) {
              dialog.dismiss();
              SharedPreferences.Editor editor = setOverlay.edit();
              editor.putBoolean("overlaypref", false);
              editor.commit();
          }
      });
      dialog.show();
  } 
Run Code Online (Sandbox Code Playgroud)