2

나는 붕괴 도구 모음을 가지고 있지만, 나는 하나님의 사랑에 대한 이유는 그것이 내가 붕괴로 원하는대로 변경되지 않는 그림을 알아낼 수 없다 ... 여기 내 XML 코드는 툴바 축소 도구입니다.축소 된 툴바의 색상을 어떻게 변경합니까?

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appBar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/FrontierTheme"> 
     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:contentScrim="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed" 
      app:expandedTitleMarginEnd="64dp" 
      app:expandedTitleMarginStart="48dp"> 
      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="200dp" 
       android:scaleType="centerCrop" 
       app:layout_collapseMode="parallax" 
       android:src="@drawable/background" 
       android:id="@+id/profileView_imageView"/> 
      <android.support.v7.widget.Toolbar 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:app="http://schemas.android.com/apk/res-auto" 
       android:layout_width="match_parent" android:layout_height="wrap_content" 
       android:id="@+id/toolbarProfileViewID" 
       android:minHeight="?attr/actionBarSize" 
       app:theme="@style/FrontierTheme" 
       app:layout_collapseMode="pin"> 
      </android.support.v7.widget.Toolbar> 
     </android.support.design.widget.CollapsingToolbarLayout> 
     <android.support.design.widget.TabLayout 
      android:id="@+id/tabLayout" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:layout_gravity="bottom" 
      android:background="@color/mainColor" 
      app:tabMode="scrollable" 
      app:tabTextColor="@color/white"/> 
    </android.support.design.widget.AppBarLayout> 
    <android.support.v4.view.ViewPager 
     android:id="@+id/tab_viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 
</android.support.design.widget.CoordinatorLayout> 

여기

<style name="FrontierTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
     <item name="android:colorPrimary">#5F021F</item> 
     <item name="android:colorPrimaryDark">#5E152C</item> 
     <item name="android:colorAccent">#BCBCBC</item> 
     <item name="android:textColor">#FFFFFF</item> 
    </style> 

그리고 여기 내 안드로이드 매니페스트입니다 (내가 일반 styles.xml 파일에 아무것도 필요 없다) 내 styles.v21입니다. 이 붕괴 할 때

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    package="com.daprlabs.swipedeck" > 
<uses-sdk 
     android:minSdkVersion="7" 
     android:targetSdkVersion="23" /> 
    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:largeHeap="true" 
     android:supportsRtl="true" 
     android:theme="@style/FrontierTheme" 
     android:name=".ApplicationEnvironment"> 
     <activity 
      android:name=".ActivityCenter"> <!--android:theme="@style/TestTheme" --> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
<activity android:name=".ProfileView.ProfileView" 
      android:label="Frontier" /> 
    </application> 

</manifest> 

현재, 색상은 흰색입니다 ...하지만 난이 16 진수가되고 싶어요 : #5F021F

+0

잘 작동합니다. 체크 아웃 [여기] (https://stackoverflow.com/questions/30619598/android-material-design-how-to-change-background-color-of-toolbar-after-collap/47628602#47628602) –

답변

11

그것이 붕괴의 여부를 알고하는 AppBarLayoutaddOnOffsetChangedListener 리스너를 추가하고, setBackgroundColor을 사용하여 색상을 변경하십시오. 좋아요 :

//Set a listener to know the current visible state of CollapseLayout 
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { 
    int scrollRange = -1; 

    @Override 
    public void onOffsetChanged(final AppBarLayout appBarLayout, int verticalOffset) { 
     //Initialize the size of the scroll 
     if (scrollRange == -1) { 
      scrollRange = appBarLayout.getTotalScrollRange(); 
     } 
     //Check if the view is collapsed 
     if (scrollRange + verticalOffset == 0) { 
      toolbar.setBackgroundColor(ContextCompat.getColor(mContext, R.color.YOUR_COLLAPSED_COLOR)); 
     }else{ 
      toolbar.setBackgroundColor(ContextCompat.getColor(mContext, R.color.OTHER_COLOR)); 
     } 
    } 
}); 
+0

고마워 친구 그 트릭을 했어! – TheQ

관련 문제