Set collapsing toolbar scrims programmatically

pull/935/head
Alex Baker 4 years ago
parent f59015c7a9
commit 71f7ce8be3

@ -294,7 +294,7 @@ public class MainActivity extends InjectingAppCompatActivity
private void applyTheme() {
ThemeColor filterColor = getFilterColor();
filterColor.applyToStatusBar(binding.drawerLayout);
filterColor.setStatusBarColor(binding.drawerLayout);
filterColor.applyToNavigationBar(this);
filterColor.applyTaskDescription(
this, filter == null ? getString(R.string.app_name) : filter.listingTitle);

@ -33,6 +33,7 @@ import butterknife.ButterKnife;
import butterknife.OnClick;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.AppBarLayout.Behavior;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.common.base.Strings;
import com.mapbox.android.core.location.LocationEngineCallback;
import com.mapbox.android.core.location.LocationEngineProvider;
@ -87,6 +88,9 @@ public class LocationPickerActivity extends InjectingAppCompatActivity
@BindView(R.id.app_bar_layout)
AppBarLayout appBarLayout;
@BindView(R.id.collapsing_toolbar_layout)
CollapsingToolbarLayout toolbarLayout;
@BindView(R.id.coordinator)
CoordinatorLayout coordinatorLayout;
@ -166,6 +170,7 @@ public class LocationPickerActivity extends InjectingAppCompatActivity
ThemeColor themeColor = theme.getThemeColor();
themeColor.applyToStatusBarIcons(this);
themeColor.applyToNavigationBar(this);
themeColor.setStatusBarColor(toolbarLayout);
boolean dark = theme.getThemeBase().isDarkTheme(this);
map.init(getSupportFragmentManager(), this, dark);

@ -16,6 +16,7 @@ import androidx.annotation.RequiresApi;
import androidx.appcompat.widget.Toolbar;
import androidx.core.graphics.ColorUtils;
import androidx.drawerlayout.widget.DrawerLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import org.tasks.R;
import org.tasks.dialogs.ColorPickerDialog;
import org.tasks.ui.MenuColorizer;
@ -154,13 +155,13 @@ public class ThemeColor implements ColorPickerDialog.Pickable {
public void setStatusBarColor(Activity activity) {
if (atLeastLollipop()) {
activity.getWindow().setStatusBarColor(getColorPrimaryVariant());
activity.getWindow().setStatusBarColor(colorPrimaryVariant);
}
}
public void applyToStatusBar(DrawerLayout drawerLayout) {
public void setStatusBarColor(DrawerLayout drawerLayout) {
if (atLeastLollipop()) {
drawerLayout.setStatusBarBackgroundColor(getColorPrimaryVariant());
drawerLayout.setStatusBarBackgroundColor(colorPrimaryVariant);
}
if (atLeastMarshmallow()) {
int systemUiVisibility = applyLightStatusBarFlag(drawerLayout.getSystemUiVisibility());
@ -168,6 +169,11 @@ public class ThemeColor implements ColorPickerDialog.Pickable {
}
}
public void setStatusBarColor(CollapsingToolbarLayout layout) {
layout.setContentScrimColor(colorPrimary);
layout.setStatusBarScrimColor(colorPrimaryVariant);
}
public void applyToStatusBarIcons(Activity activity) {
if (atLeastMarshmallow()) {
View decorView = activity.getWindow().getDecorView();
@ -249,10 +255,6 @@ public class ThemeColor implements ColorPickerDialog.Pickable {
return actionBarTint;
}
private int getColorPrimaryVariant() {
return colorPrimaryVariant;
}
public void apply(Toolbar toolbar) {
toolbar.setBackgroundColor(getPrimaryColor());
MenuColorizer.colorToolbar(toolbar, actionBarTint);

@ -15,12 +15,11 @@
android:theme="?attr/overlay_theme">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:statusBarScrim="?attr/colorPrimaryVariant"
app:titleEnabled="false">
<androidx.constraintlayout.widget.ConstraintLayout

Loading…
Cancel
Save