File tree 2 files changed +47
-9
lines changed
sample/src/main/java/com/github/amlcurran/showcaseview/sample
2 files changed +47
-9
lines changed Original file line number Diff line number Diff line change 8
8
9
9
import com .espian .showcaseview .sample .R ;
10
10
import com .github .amlcurran .showcaseview .ShowcaseView ;
11
+ import com .github .amlcurran .showcaseview .targets .ViewTarget ;
11
12
12
13
public class ActionItemsSampleActivity extends AppCompatActivity {
13
14
14
15
@ Override
15
16
protected void onCreate (@ Nullable Bundle savedInstanceState ) {
16
17
super .onCreate (savedInstanceState );
17
18
setContentView (R .layout .activity_action_items );
18
- Toolbar viewById = (Toolbar ) findViewById (R .id .toolbar );
19
- setSupportActionBar (viewById );
19
+ Toolbar toolbar = (Toolbar ) findViewById (R .id .toolbar );
20
+ setSupportActionBar (toolbar );
21
+ getSupportActionBar ().setDisplayHomeAsUpEnabled (true );
20
22
21
- new ShowcaseView .Builder (this )
22
- .withMaterialShowcase ()
23
- .setTarget (new ToolbarActionItemTarget (viewById , R .id .menu_item1 ))
24
- .setStyle (R .style .CustomShowcaseTheme2 )
25
- .setContentText ("Here's how to highlight items on a toolbar" )
26
- .build ()
27
- .show ();
23
+ try {
24
+ ViewTarget navigationButtonViewTarget = ViewTargets .navigationButtonViewTarget (toolbar );
25
+ new ShowcaseView .Builder (this )
26
+ .withMaterialShowcase ()
27
+ .setTarget (navigationButtonViewTarget )
28
+ .setStyle (R .style .CustomShowcaseTheme2 )
29
+ .setContentText ("Here's how to highlight items on a toolbar" )
30
+ .build ()
31
+ .show ();
32
+ } catch (ViewTargets .MissingViewException e ) {
33
+ e .printStackTrace ();
34
+ }
28
35
}
29
36
30
37
@ Override
Original file line number Diff line number Diff line change
1
+ package com .github .amlcurran .showcaseview .sample ;
2
+
3
+ import android .support .v7 .widget .Toolbar ;
4
+ import android .view .View ;
5
+
6
+ import com .github .amlcurran .showcaseview .targets .ViewTarget ;
7
+
8
+ import java .lang .reflect .Field ;
9
+
10
+ public class ViewTargets {
11
+
12
+ public static ViewTarget navigationButtonViewTarget (Toolbar toolbar ) throws MissingViewException {
13
+ try {
14
+ Field field = Toolbar .class .getDeclaredField ("mNavButtonView" );
15
+ field .setAccessible (true );
16
+ View navigationView = (View ) field .get (toolbar );
17
+ return new ViewTarget (navigationView );
18
+ } catch (NoSuchFieldException e ) {
19
+ throw new MissingViewException (e );
20
+ } catch (IllegalAccessException e ) {
21
+ throw new MissingViewException (e );
22
+ }
23
+ }
24
+
25
+ public static class MissingViewException extends Exception {
26
+
27
+ public MissingViewException (Throwable throwable ) {
28
+ super (throwable );
29
+ }
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments