com.google.android.material.appbar.CollapsingToolbarLayout Java Examples

The following examples show how to use com.google.android.material.appbar.CollapsingToolbarLayout. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java    From ui with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar =  findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    collapsingToolbarLayout.setTitle(getResources().getString(R.string.app_name));


    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    dynamicToolbarColor();

    toolbarTextAppernce();
}
 
Example #2
Source File: AboutActivity.java    From PocketMaps with MIT License 6 votes vote down vote up
@Override protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        CollapsingToolbarLayout toolBarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
        toolBarLayout.setTitle(getTitle());

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override public void onClick(View view) {
                //                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG).setAction
                // ("Action", null)
                //                        .show();

                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://github.com/junjunguo/PocketMaps/")));

            }
        });

        //         set status bar
//        new SetStatusBarColor().setSystemBarColor(findViewById(R.id.statusBarBackgroundSettings),
//                getResources().getColor(R.color.my_primary_dark), this);
    }
 
Example #3
Source File: ScrollingActivity.java    From GSYVideoPlayer with Apache License 2.0 6 votes vote down vote up
private void initView() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    detailPlayer = (LandLayoutVideo) findViewById(R.id.detail_player);
    root = (CoordinatorLayout) findViewById(R.id.root_layout);

    setSupportActionBar(toolbar);
    toolBarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
    toolBarLayout.setTitle(getTitle());

    fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            detailPlayer.startPlayLogic();
            root.removeView(fab);
        }
    });

    appBar = (AppBarLayout) findViewById(R.id.app_bar);
    appBar.addOnOffsetChangedListener(appBarStateChangeListener);
}
 
Example #4
Source File: TestUtilsActions.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/** Sets title on the {@link CollapsingToolbarLayout}. */
public static ViewAction setTitle(final CharSequence title) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(CollapsingToolbarLayout.class);
    }

    @Override
    public String getDescription() {
      return "set toolbar title";
    }

    @Override
    public void perform(UiController uiController, View view) {
      uiController.loopMainThreadUntilIdle();

      CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) view;
      collapsingToolbarLayout.setTitle(title);

      uiController.loopMainThreadUntilIdle();
    }
  };
}
 
Example #5
Source File: CollapsingToolbarLayoutActions.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
public static ViewAction setContentScrimColor(@ColorInt final int color) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isDisplayed();
    }

    @Override
    public String getDescription() {
      return "Set the content scrim to a color";
    }

    @Override
    public void perform(UiController uiController, View view) {
      uiController.loopMainThreadUntilIdle();
      CollapsingToolbarLayout ctl = (CollapsingToolbarLayout) view;
      ctl.setContentScrimColor(color);
      uiController.loopMainThreadUntilIdle();
    }
  };
}
 
Example #6
Source File: DemoActivity.java    From StickyHeaders with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(getContentViewLayout());

    appBarLayout = (AppBarLayout) findViewById(R.id.appBar);
    collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsingToolbarLayout);
    recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    progressBar = (ProgressBar) findViewById(R.id.progress);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    if (toolbar != null) {
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }
}
 
Example #7
Source File: OdysseyMainActivity.java    From odyssey with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void setupToolbarImage(Bitmap bm) {
    ImageView collapsingImage = findViewById(R.id.collapsing_image);
    if (collapsingImage != null) {
        collapsingImage.setImageBitmap(bm);

        // FIXME DIRTY HACK: Manually fix the toolbar size to the screen width
        CollapsingToolbarLayout toolbar = findViewById(R.id.collapsing_toolbar);
        AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();

        params.height = getWindow().getDecorView().getMeasuredWidth();

        // Always expand the toolbar to show the complete image
        AppBarLayout appbar = findViewById(R.id.appbar);
        appbar.setExpanded(true, false);
    }
}
 
Example #8
Source File: DynamicBottomAppBar.java    From dynamic-support with Apache License 2.0 5 votes vote down vote up
@Override
public void setColor() {
    if (mColor != WidgetDefaults.ADS_COLOR_UNKNOWN) {
        if (isBackgroundAware() && mContrastWithColor != WidgetDefaults.ADS_COLOR_UNKNOWN) {
            mColor = DynamicColorUtils.getContrastColor(mColor, mContrastWithColor);
        }

        if (getParent() != null && getParent() instanceof CollapsingToolbarLayout) {
            setBackgroundColor(Color.TRANSPARENT);
        } else {
            setBackgroundColor(mColor);
        }
    }
}
 
Example #9
Source File: DesignModuleAttributeHelper.java    From proteus with Apache License 2.0 5 votes vote down vote up
static void setParallaxMultiplier(View v, String multiplier) {
  CollapsingToolbarLayout.LayoutParams layoutParams = getLayoutParams(v);
  if (null != layoutParams && !TextUtils.isEmpty(multiplier)) {
    layoutParams.setParallaxMultiplier(ParseHelper.parseFloat(multiplier));
  }

}
 
Example #10
Source File: DesignModuleAttributeHelper.java    From proteus with Apache License 2.0 5 votes vote down vote up
static void setCollapseMode(View v, String mode) {
  CollapsingToolbarLayout.LayoutParams layoutParams = getLayoutParams(v);
  if (null != layoutParams) {
    Integer collapseMode = sCollapseModeMap.get(mode);
    if (null != collapseMode) {
      layoutParams.setCollapseMode(collapseMode);
    }
  }
}
 
Example #11
Source File: DesignModuleAttributeHelper.java    From proteus with Apache License 2.0 5 votes vote down vote up
private static CollapsingToolbarLayout.LayoutParams getLayoutParams(View v) {
  initialize();
  CollapsingToolbarLayout.LayoutParams result = null;
  ViewGroup.LayoutParams layoutParams = v.getLayoutParams();
  if (null != layoutParams && layoutParams instanceof CollapsingToolbarLayout.LayoutParams) {
    result = (CollapsingToolbarLayout.LayoutParams) layoutParams;
  }
  return result;
}
 
Example #12
Source File: DesignModuleAttributeHelper.java    From proteus with Apache License 2.0 5 votes vote down vote up
private static void initialize() {
  if (!sInitialized) {
    sInitialized = true;

    sCollapseModeMap.put(COLLAPSE_MODE_OFF, CollapsingToolbarLayout.LayoutParams.COLLAPSE_MODE_OFF);
    sCollapseModeMap.put(COLLAPSE_MODE_PARALLAX, CollapsingToolbarLayout.LayoutParams.COLLAPSE_MODE_PARALLAX);
    sCollapseModeMap.put(COLLAPSE_MODE_PIN, CollapsingToolbarLayout.LayoutParams.COLLAPSE_MODE_PIN);
  }
}
 
Example #13
Source File: CollapsingToolbarLayoutActivity.java    From Android-skin-support with MIT License 5 votes vote down vote up
private void initParallaxValues() {
    CollapsingToolbarLayout.LayoutParams petDetailsLp =
            (CollapsingToolbarLayout.LayoutParams) mIvPlaceholder.getLayoutParams();

    CollapsingToolbarLayout.LayoutParams petBackgroundLp =
            (CollapsingToolbarLayout.LayoutParams) mFlTitleContainer.getLayoutParams();

    petDetailsLp.setParallaxMultiplier(0.9f);
    petBackgroundLp.setParallaxMultiplier(0.3f);

    mIvPlaceholder.setLayoutParams(petDetailsLp);
    mFlTitleContainer.setLayoutParams(petBackgroundLp);
}
 
Example #14
Source File: SkinMaterialCollapsingToolbarLayout.java    From Android-skin-support with MIT License 5 votes vote down vote up
public SkinMaterialCollapsingToolbarLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.CollapsingToolbarLayout, defStyleAttr,
            R.style.Widget_Design_CollapsingToolbar);
    mContentScrimResId = a.getResourceId(R.styleable.CollapsingToolbarLayout_contentScrim, INVALID_ID);
    mStatusBarScrimResId = a.getResourceId(R.styleable.CollapsingToolbarLayout_statusBarScrim, INVALID_ID);
    a.recycle();
    applyContentScrimResource();
    applyStatusBarScrimResource();
    mBackgroundTintHelper = new SkinCompatBackgroundHelper(this);
    mBackgroundTintHelper.loadFromAttributes(attrs, 0);
}
 
Example #15
Source File: EventActivity.java    From haven with GNU General Public License v3.0 5 votes vote down vote up
/**
 * On event fetched update {@link #mEvent} and set Activity title
 */
private void onEventFetched(@NonNull Event event) {
    mEvent = event;
    String title = mEvent.getStartTime().toLocaleString();
    setTitle(title);
    CollapsingToolbarLayout collapsingToolbarLayout = findViewById(R.id.toolbar_layout);
    collapsingToolbarLayout.setTitle(title);

    //((TextView)findViewById(R.id.toolbar_title)).setText(mEvent.getStartTime().toLocaleString());
}
 
Example #16
Source File: SetupBigHeaderActivity.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (mCustomContentViewId != 0)
        setContentView(mCustomContentViewId);
    else
        setContentView(R.layout.activity_setup_big_header);

    AppBarLayout appBar = findViewById(R.id.appbar);

    CollapsingToolbarLayout toolbarLayout = findViewById(R.id.toolbar_layout);

    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mLayout = findViewById(R.id.layout);
    mLayout.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
        int height = mLayout.getHeight();
        CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams)
                appBar.getLayoutParams();
        params.height = height / 3;
        appBar.setLayoutParams(params);

        int childHeight = (mContentView != null ? mContentView.getHeight() : 0);
        if (mContentView instanceof NestedScrollView)
            childHeight = ((NestedScrollView) mContentView).getChildAt(0).getHeight();
        boolean needsScroll = (mContentView != null && childHeight > height - params.height);

        AppBarLayout.LayoutParams paramsToolbar = (AppBarLayout.LayoutParams) toolbarLayout.getLayoutParams();
        paramsToolbar.setScrollFlags(needsScroll
                ? (AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED)
                : 0);
        toolbarLayout.setLayoutParams(paramsToolbar);
    });
}
 
Example #17
Source File: DynamicToolbar.java    From dynamic-support with Apache License 2.0 5 votes vote down vote up
@Override
public void setColor() {
    if (mColor != WidgetDefaults.ADS_COLOR_UNKNOWN) {
        if (isBackgroundAware() && mContrastWithColor != WidgetDefaults.ADS_COLOR_UNKNOWN) {
            mColor = DynamicColorUtils.getContrastColor(mColor, mContrastWithColor);
        }

        if (getParent() != null && getParent() instanceof CollapsingToolbarLayout) {
            setBackgroundColor(Color.TRANSPARENT);
        } else {
            setBackgroundColor(mColor);
        }
    }
}
 
Example #18
Source File: OdysseyMainActivity.java    From odyssey with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setupToolbar(String title, boolean scrollingEnabled, boolean drawerIndicatorEnabled, boolean showImage) {
    // set drawer state
    mDrawerToggle.setDrawerIndicatorEnabled(drawerIndicatorEnabled);

    ImageView collapsingImage = findViewById(R.id.collapsing_image);
    View collapsingImageGradientTop = findViewById(R.id.collapsing_image_gradient_top);
    View collapsingImageGradientBottom = findViewById(R.id.collapsing_image_gradient_bottom);
    if (collapsingImage != null && collapsingImageGradientTop != null && collapsingImageGradientBottom != null) {
        if (showImage) {
            collapsingImage.setVisibility(View.VISIBLE);
            collapsingImageGradientTop.setVisibility(View.VISIBLE);
            collapsingImageGradientBottom.setVisibility(View.VISIBLE);
        } else {
            collapsingImage.setVisibility(View.GONE);
            collapsingImage.setImageDrawable(null);
            collapsingImageGradientTop.setVisibility(View.GONE);
            collapsingImageGradientBottom.setVisibility(View.GONE);
        }
    }
    // set scrolling behaviour
    CollapsingToolbarLayout toolbar = findViewById(R.id.collapsing_toolbar);
    AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
    params.height = -1;

    if (scrollingEnabled && !showImage) {
        toolbar.setTitleEnabled(false);
        setTitle(title);

        params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL + AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED + AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
    } else if (!scrollingEnabled && showImage && collapsingImage != null) {
        toolbar.setTitleEnabled(true);
        toolbar.setTitle(title);

        params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED + AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL);
    } else {
        toolbar.setTitleEnabled(false);
        setTitle(title);
        params.setScrollFlags(0);
    }
}
 
Example #19
Source File: AbsAboutActivity.java    From about-page with Apache License 2.0 4 votes vote down vote up
public CollapsingToolbarLayout getCollapsingToolbar() {
  return collapsingToolbar;
}
 
Example #20
Source File: MainActivity.java    From java-android-developertools with Apache License 2.0 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        // TODO: Find a better solution for the icon - we have to manually remove it because of how we use the fragment manager and the other fragments.
//        if (savedInstanceState == null) {
//            ImageView logoImageView = new ImageView(getApplicationContext());
//            logoImageView.eetImageDrawable(getResources().getDrawable(R.drawable.collapsable_toolbar_icon));
//            ((ScrollView) findViewById(R.id.layout_content)).addView(logoImageView);
//        }
        if (savedInstanceState != null) {
            ViewGroup viewGroup = (ViewGroup) findViewById(R.id.layout_content);
            if (viewGroup != null) {
                viewGroup.removeAllViews();
            }
        }

//        AppBarLayout appbarLayout = (AppBarLayout) findViewById(R.id.appBarLayout);
//        CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appbarLayout.getLayoutParams();
//        AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();
//        if (behavior != null) {
//            behavior.onNestedFling((CoordinatorLayout) findViewById(R.id.coordinatorLayout), appbarLayout, null, 0, 10000, true);
//        }

        try {
            sdkVersion = Integer.parseInt(Build.VERSION.SDK);
        } catch (NumberFormatException e) {
            /* no-op */
        }

        Toolbar toolbar = ((Toolbar) findViewById(R.id.toolbar));
        if (findViewById(R.id.layout_content) != null) {
            // The detail container view will be present only in the
            // large-screen layouts (res/values-large and
            // res/values-sw600dp). If this view is present, then the
            // activity should be in two-pane mode.
            twoPaneMode = true;
            toolbar.setTitle(getString(R.string.app_name));

        } else { // Not two pane
            if (sdkVersion > 7) { // TODO: The collapsing toolbar and nested scroll view and stuff hardly worked on Xperia X10 (2.3.3/9) and Nexus One (2.3.6/10), any chance to get it to work?
                ((CollapsingToolbarLayout) findViewById(R.id.collapsingToolbarLayout)).setTitle(getString(R.string.app_name));
            } else {
                toolbar.setTitle(getString(R.string.app_name));
            }
        }
        setSupportActionBar(toolbar);

        if (sdkVersion >= 18 && sdkVersion <= 19) { // Android 4.3-4.4
            findViewById(R.id.textView_settings_permissions).setVisibility(View.VISIBLE);
            findViewById(R.id.include_list_divider).setVisibility(View.VISIBLE);
        }
        if (sdkVersion < 15) {
            findViewById(R.id.textView_app_cleanStatusBar).setVisibility(View.GONE);
            findViewById(R.id.include_list_divider_clean_status_bar).setVisibility(View.GONE);
        }
    }
 
Example #21
Source File: DynamicActivity.java    From dynamic-support with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the collapsing toolbar layout used by this activity.
 *
 * @return The collapsing toolbar layout used by this activity.
 */
public CollapsingToolbarLayout getCollapsingToolbarLayout() {
    return mCollapsingToolbarLayout;
}
 
Example #22
Source File: AbsAboutActivity.java    From about-page with Apache License 2.0 votes vote down vote up
protected void onTitleViewCreated(@NonNull CollapsingToolbarLayout collapsingToolbar) {}