material-components / material-components/material-components-android

[CollapsingToolbarLayout] Is there any way to make expand title full width when some menu exists

Open
#3,568 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Widget: TopAppBar
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

Description: expand title width is short when some menu exists, see this picture

Expected behavior: expand title width is same with screen

Source code:

// update some codes from catalog: TopAppBarCollapsingMultilineDemoFragment.java
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
// update menu file to display more icons in toolbar
    menuInflater.inflate(R.menu.cat_topappbar_menu, menu);

    super.onCreateOptionsMenu(menu, menuInflater);
  }

  @Override
  public void onPrepareOptionsMenu(@NonNull Menu menu) {
    super.onPrepareOptionsMenu(menu);

//    CollapsingToolbarLayout collapsingToolbarLayout =
//        requireView().findViewById(R.id.collapsingtoolbarlayout);
//    @SuppressWarnings("RestrictTo")
//    int maxLines = collapsingToolbarLayout.getMaxLines();
//    for (int i = 0; i < linesMap.size(); i++) {
//      int value = linesMap.valueAt(i);
//      int itemId = linesMap.keyAt(i);
//      MenuItem item = menu.findItem(itemId);
//      CharSequence title = getString(R.string.menu_max_lines, value);
//      if (maxLines == value) {
//        SpannableString spannable = new SpannableString(title);
//        spannable.setSpan(new ForegroundColorSpan(colorPrimary), 0, title.length(), 0);
//        title = spannable;
//      }
//
//      item.setTitle(title);
//    }
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
//    CollapsingToolbarLayout collapsingToolbarLayout =
//        requireView().findViewById(R.id.collapsingtoolbarlayout);
//    collapsingToolbarLayout.setMaxLines(linesMap.get(item.getItemId(), 1));
    return super.onOptionsItemSelected(item);
  }

Minimal sample app repro: Please consider attaching a minimal sample app that reproduces the issue. This will help narrow down the conditions required for reproducing the issue, and it will speed up the bug fix process. You may attach a zip file of the sample app or link to a GitHub repo that contains the sample app.

Android API version: 29

Material Library version: 1.7.0, 1.9.0

Device: Pixel

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the behavior in TopAppBarCollapsingMultilineDemoFragment.java with the cat_topappbar_menu menu and the listed Material Library versions. Inspect CollapsingToolbarLayout's title layout when toolbar menu items are present; done means the expanded title can use the full screen width while the menu remains visible.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.