0

I'm using https://github.com/amlcurran/ShowcaseView to display ShowcaseView for Menuitems as below:

MainActivity.java:

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);



        // Set our view from the "main" layout resource
        setContentView(R.layout.activity_main);
    //getWindow().setBackgroundDrawable(null);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        //Toolbar will now take on default actionbar characteristics
        setContentView(R.layout.activity_main);

    setTitle("DDIT Results");

    try {

        new ShowcaseView.Builder(MainActivity.this)
                .withMaterialShowcase()
                .setStyle(R.style.MyTheme)
                .setTarget(new ActionItemTarget(MainActivity.this, R.id.action_notify))
                .setContentTitle("Enable Notification")
                .setContentText("Click On the Button and get notified whenever the Result-table Changes")

                .build()
        .show();
    }
    catch(Exception e)
    {
        Toast.makeText(MainActivity.this,""+e,Toast.LENGTH_LONG).show();
    }

}

Which is causing the app to be crashed.

menu_main.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">

<item android:id="@+id/action_rateus" android:title="@string/rate_us" android:orderInCategory="100" app:showAsAction="never"/>
<item android:id="@+id/action_notify" android:title="@string/notify" android:icon="@drawable/ic_notifications_none_white_24dp"
    android:orderInCategory="100" app:showAsAction="ifRoom" />

<item android:id="@+id/action_privacy_policy" android:title="Privacy Policy" android:orderInCategory="100" app:showAsAction="never"/>
<item android:id="@+id/action_email_us" android:title="@string/action_email_us" android:orderInCategory="100" app:showAsAction="never"/>
<item android:id="@+id/action_settings" android:title="@string/action_settings"
    android:orderInCategory="100" app:showAsAction="never" />

Log:

java.lang.RuntimeException: insertShowcaseViewWithType cannot be used when the theme has no ActionBar
        at com.github.amlcurran.showcaseview.targets.ActionBarReflector.getHomeButton(ActionBarReflector.java:43)
        at com.github.amlcurran.showcaseview.targets.ActionBarReflector.getActionBarView(ActionBarReflector.java:36)
        at com.github.amlcurran.showcaseview.targets.ActionItemTarget.setUp(ActionItemTarget.java:49)
        at com.github.amlcurran.showcaseview.targets.ActionItemTarget.getPoint(ActionItemTarget.java:43)
        at com.github.amlcurran.showcaseview.ShowcaseView$1.run(ShowcaseView.java:176)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5221)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

Is it possible to have the showcaseview target the specific items in the action bar? I searched for this problem and didn't come up with any solutions.Hopefully, someone recognizes this error and has a quick answer for it - otherwise I can provide more information if requested.Any help would be appriciated.

Prabhakar
  • 513
  • 1
  • 5
  • 22

2 Answers2

0

Step 1: Create a Activity class and implements it with OnClickListener.

public class MainActivity extends Activity implements View.OnClickListener {

private ImageView menuDisplayIcon;
private ShowcaseView showCaseView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // For no title
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    // For ull screen view
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    // Setting layout
    setContentView(R.layout.activity_main);
    // Initializing UI
    initUI();
    // Showcase
    showcaseUtils();

}

/**
 * Initializing UI components wrt MainActivity
 */
private void initUI() {
    menuDisplayIcon = (ImageView) findViewById(R.id.menuDisplayIcon);
}

/**
 * Showcase view
 */
private void showcaseUtils() {
    showCaseView = new ShowcaseView.Builder(this).setTarget(new ViewTarget(menuDisplayIcon))
            .setContentTitle("Title").setContentText("Description").setOnClickListener(this).build();
    showCaseView.setButtonText("Finish");
}


@Override
public void onClick(View v) {
    if (showCaseView != null) {
        showCaseView.hide();
    }
}

Step 2: Layout activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">

<include layout="@layout/actionbar_layout" />


</LinearLayout>

Step 3: Layout: actionbar_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:gravity="right">

<ImageView
    android:id="@+id/menuDisplayIcon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/settingsicon" />

</LinearLayout>

Note: Include Showcase SDk available on GitHub.

For any query feel free to ask.

Vibhor Chopra
  • 647
  • 4
  • 14
0

At this time, ShowcaseView doesn't support the latest version of AppCompat using an actionbar. You can see more details in this issue here.

My recommendation at the moment is to use an AppCompat activity with a Toolbar instead of the default ActionBar. This should work fine. There's a demo of this as an Activity, and using a Target

Alex Curran
  • 8,818
  • 6
  • 49
  • 55