0

How can I display the Tab Target only once when opening the activity for the first time? This is my code :

textView = findViewById(R.id.main_title_activity_text);

    new TapTargetSequence(this)
            .targets(
                    TapTarget.forView(textView,"Button 1","This is Button 1")
                            .outerCircleColor(R.color.orange)
                            .outerCircleAlpha(0.96f)
                            .targetCircleColor(R.color.white)
                            .titleTextSize(20)
                            .titleTextColor(R.color.white)
                            .descriptionTextSize(10)
                            .descriptionTextColor(R.color.black)
                            .textColor(R.color.black)
                            .textTypeface(Typeface.SANS_SERIF)
                            .dimColor(R.color.black)
                            .drawShadow(true)
                            .cancelable(false)
                            .tintTarget(true)
                            .transparentTarget(true)
                            .targetRadius(60)
                   
            );
Rohit5k2
  • 17,948
  • 8
  • 45
  • 57

1 Answers1

0

//If you have your sharedPreferecne class use that or else use below

 public class SharedPref {
 private static SharedPreferences mSharedPref;
 public static final String IS_SHOWN = "IS_SHOWN";

 private SharedPref() {
 }

 public static void init(Context context) {
    if (mSharedPref == null)
        mSharedPref = 
 context.getSharedPreferences(context.getPackageName(), 
Activity.MODE_PRIVATE);
}


public static boolean read(String key, boolean defValue) {
    return mSharedPref.getBoolean(key, defValue);
}

public static void write(String key, boolean value) {
    SharedPreferences.Editor prefsEditor = mSharedPref.edit();
    prefsEditor.putBoolean(key, value);
    prefsEditor.commit();
 }

}

 //Put  this code in onCreate
 @Override
 protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    SharedPref.init(getApplicationContext());

    if (!SharedPref.read(SharedPref.IS_SHOWN, false)) {
        SharedPref.write(SharedPref.IS_SHOWN, true);
        TapTargetView.showFor(this, 
  TapTarget.forView(findViewById(R.id.text_1)
                                , "This is a target", "We have the best 
 targets, believe me")
                        
 .outerCircleColor(R.color.dark_blue).outerCircleAlpha(0.96f)
                        
  .targetCircleColor(R.color.white).titleTextSize(20)
                        .titleTextColor(R.color.white);

    }
}