2
이 도구 모음을 붕괴에 대한 나의 XML 코드는

축소 버튼,
CollapsingToolbarLayout가

<android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapsing_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:expandedTitleGravity="left" 
     app:expandedTitleMarginTop="-10dp" 
     app:expandedTitleMarginStart="10dp" 
     app:contentScrim="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="130dp"> 

      <ImageView 
       android:id="@+id/ivCImage" 
       android:layout_width="match_parent" 
       android:layout_height="130dp" 
       android:scaleType="fitXY" 
       android:src="@drawable/image_place_holder" /> 

     </RelativeLayout> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      app:layout_collapseMode="pin"> 
      </android.support.v7.widget.Toolbar> 

    </android.support.design.widget.CollapsingToolbarLayout> 

</android.support.design.widget.AppBarLayout> 

그리고 제가 코딩했을 것입니다,

private CollapsingToolbarLayout collapsingToolbarLayout = null; 

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 
    ActionBar actionBar = getSupportActionBar(); 
    actionBar.setDisplayHomeAsUpEnabled(true); 

    collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); 

그것은 아이콘을 다시 보여주는를 다시 설정하는 방법 항상 그래야하지만 CollapsingToolbarLayout이 축소되면 집 (뒤로) 아이콘을 표시하거나 사용하고 싶습니다. 어떻게하면 될까요? 도움이나 제안을 주시면 감사하겠습니다.

답변

0

먼저, 플래그

boolean FLAG_COLLAPSED = true; //Change this according to your view 

이 그런 다음 AppBar 당신의 backpress 방법 지금

AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.AppBarLayout); 
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { 
    @Override 
    public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { 
     if (Math.abs(verticalOffset) == appBarLayout.getTotalScrollRange()) { 
      // Collapsed 
      FLAG_COLLAPSED = true; 
     } else if (verticalOffset == 0) { 
      FLAG_COLLAPSED = false; 
     } else { 
      // Somewhere in between 
     } 
    } 
});); 

에 리스너를 추가를 만들

@Override 
public void onBackPressed() { 
    if(FLAG_COLLAPSED){ 
     super.onBackPressed(); 
    } 
} 
+0

내가 아이콘을 다시 표시 할 수 있습니다. – Exigente05

0

그래, 난 쉽게 이런 짓을했습니다, 툴바에서 간단하게 뒤로 탐색을 활성화해야합니다. 툴바 축소와 관련이 없으며, 매니페스트 파일에서 수행해야합니다. 서면 부모 활동 이름과 같이 활동에 상위 클래스를 표시합니다. 붕괴에

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 
    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
    getSupportActionBar().setDisplayShowHomeEnabled(true); 
    initCollapsingToolbar(); 

: 내가 원하는하지만 붕괴 때 지금 문제가 "collapsingToolbarLayout"제목이 지금 보여주는대로

private void initCollapsingToolbar() { 
    final CollapsingToolbarLayout collapsingToolbar = 
      (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); 
    collapsingToolbar.setTitle(" "); 
    AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appbar); 
    appBarLayout.setExpanded(true); 

    appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { 
     boolean isShow = false; 
     int scrollRange = -1; 

     @Override 
     public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { 
      if (scrollRange == -1) { 
       scrollRange = appBarLayout.getTotalScrollRange(); 
      } 
      if (scrollRange + verticalOffset == 0) { 
       collapsingToolbar.setTitle(getString(R.string.Yoga_tips)); 
       isShow = true; 
      } else if (isShow) { 
       collapsingToolbar.setTitle(" "); 
       isShow = false; 
      } 
     } 
    }); 
}