2017-05-10 4 views
-1

メニューからオーバーフローアイコンのショーケースを表示したい。オーバーフローアイコンへの参照を表示する

これは私のコードです:

ShowcaseConfig config = new ShowcaseConfig(); 
config.setDelay(500); // half second between each showcase view 

MaterialShowcaseSequence sequence = new MaterialShowcaseSequence(this, "5"); 

sequence.setConfig(config); 
sequence.addSequenceItem(((ViewGroup) tabLayout.getChildAt(0)).getChildAt(0), 
     "Sync your data by turn on the switch", "GOT IT"); 

私は次のショーケースの配列を付加するために、オーバーフロー・アイコンのViewを参照する必要があります。そのViewへの参照を取得する方法

sequence.addSequenceItem(?, "Click here to display menu", "GOT IT"); 

を?

答えて

0

オーバーフローアイコンのViewを取得するのはちょっと難しいことです。

This答えはそれを行う方法を指摘します。要約すると、以下の変更が行われる必要があります。

styles.xmlで:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    ... 
    <item name="actionOverflowButtonStyle">@style/MyActionOverflowButtonStyle</item> 
</style> 

<style name="MyActionOverflowButtonStyle" parent="Widget.AppCompat.ActionButton.Overflow"> 
    <item name="android:contentDescription">@string/my_custom_content_description</item> 
</style> 

strings.xmlで:

<string name="my_custom_content_description">some description</string> 

onCreate()活動の中:

// The content description used to locate the overflow button 
final String overflowDesc = getString(R.string.my_custom_content_description); 
// The top-level window 
final ViewGroup decor = (ViewGroup) getWindow().getDecorView(); 
// Wait until decor view is laid out 
decor.post(new Runnable() { 
    @Override 
    public void run() { 
     // The List that contains the matching views 
     final ArrayList<View> outViews = new ArrayList<>(); 
     // Traverse the view-hierarchy and locate the overflow button 
     decor.findViewsWithText(outViews, overflowDesc, 
       View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); 
     // Guard against any errors 
     if (outViews.isEmpty()) { 
      return; 
     } 
     // Do something with the view 
     final ImageView overflowIcon = (ImageView) outViews.get(0); 
     sequence.addSequenceItem(overflowIcon, "Click here to display menu", "GOT IT"); 
    } 
}); 
関連する問題