измените цвет панели инструментов, когда она рухнула в android [duplicate]

Вместо словаря вы также можете использовать namedtuple из модуля коллекций, что упрощает доступ.

например:

#using dictionary variables = {} variables["first"] = 34 variables["second"] = 45 print variables["first"], variables["second"] #using namedtuple Variables = namedtuple('Variables', ['first', 'second']) vars = Variables(34, 45) print vars.first, vars.second
33
задан Eli Davila 3 June 2015 в 12:03
поделиться

6 ответов

Я думаю, что вы после app:contentScrim.

<android.support.design.widget.CollapsingToolbarLayout
    ...
    app:contentScrim="?attr/colorPrimary">
    <!-- Toolbar and ImageView here -->
</android.support.design.widget.CollapsingToolbarLayout>
63
ответ дан Jimeux 21 August 2018 в 14:00
поделиться
  • 1
    Когда я поворачиваю свой телефон, это приложение CollapsingToolbarLayout: contentScrim = & quot; attr / colorPrimary & quot; вызывает android.view.InflateException Ошибка раздувания класса & lt; unknown & gt; , другие говорят, чтобы заменить цвет? attr @ color или @ dimen и т. д., но они не распознаются приложением: ... Что мне делать? благодаря – Ashraf Alshahawy 14 April 2016 в 04:54
  • 2
    Не могли бы вы ELI5 понять, что означает Scrim? – Sudhir Khanger 11 December 2016 в 07:05
  • 3
    @SudhirKhanger Мне также было любопытно. Похоже, что они относятся к устройству, используемому в театре: «кусок марлевой ткани, который кажется непрозрачным до тех пор, пока не будет освещен сзади, используется в качестве экрана или фона». google.com/search?q=scrim – Nolan Amy 2 August 2018 в 19:49
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
            R.drawable.header);

    Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
        @SuppressWarnings("ResourceType")

        @Override
        public void onGenerated(Palette palette) {
            Palette.Swatch vibrant =
                    palette.getVibrantSwatch();

            if (vibrant != null) {

                collapsingToolbar.setBackgroundColor(getResources().getColor(R.color.cpb_blue));
                collapsingToolbar.setStatusBarScrimColor(getResources().getColor(R.color.cpb_blue));
                collapsingToolbar.setContentScrimColor(getResources().getColor(R.color.cpb_blue));

            }
        }

    });
-1
ответ дан Aravind Cse 21 August 2018 в 14:00
поделиться

Сначала удалите

app:contentScrim="?attr/colorPrimary"> 

из CollapsingToolbarLayout

Добавить библиотеку

compile 'com.android.support:palette-v7:23.2.1'

И добавьте ниже код в java-код

    Bitmap bitmap = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.ny);
    Palette.generateAsync(bitmap,
            new Palette.PaletteAsyncListener() {
                @Override
                public void onGenerated(Palette palette) {
                    Palette.Swatch vibrant =
                            palette.getVibrantSwatch();
                    int mutedColor = palette.getVibrantSwatch().getRgb();
                    if (vibrant != null) {
                        // If we have a vibrant color
                        // update the title TextView
                        collapseToolbar.setBackgroundColor(mutedColor);
                        //  mutedColor = palette.getMutedColor(R.attr.colorPrimary);
                        collapseToolbar.setStatusBarScrimColor(palette.getDarkMutedColor(mutedColor));
                        collapseToolbar.setContentScrimColor(palette.getMutedColor(mutedColor));

                    }
                }
            });
11
ответ дан Ashish 21 August 2018 в 14:00
поделиться
  • 1
    generateAsync устарел и не меняет мою сторону, хотя после удаления app:contentScrim="?attr/colorPrimary" любая помощь? – blueware 2 March 2017 в 09:00

Просто используйте CollapsingToolbarLayout XML-атрибут contentScrim, чтобы установить цвет фона Toolbar, когда он находится в режиме collapsed.

app:contentScrim="YOUR_TOOLBAR_COLOR"

Вот пример:

<android.support.design.widget.CollapsingToolbarLayout
    android:id="@+id/collapsing_toolbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    app:contentScrim="?attr/colorPrimary"
    app:layout_scrollFlags="scroll|exitUntilCollapsed">

    <ImageView
        android:id="@+id/img_group_photo"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:scaleType="centerCrop"
        app:layout_collapseMode="parallax" />

    <android.support.v7.widget.Toolbar
        android:id="@+id/anim_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:layout_collapseMode="pin"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>

Надеюсь, это поможет ~

5
ответ дан Ferdous Ahamed 21 August 2018 в 14:00
поделиться

Вы можете использовать прослушиватель смещения AppBarLayout и изменить атрибуты CollapsingTollbar в соответствии с желаемым поведением.

appBarLayout.addOnOffsetChangedListener { _, verticalOffSet ->
            if (Math.abs(verticalOffSet) == appBarLayout.totalScrollRange) {
                //Collapsed
                toolBar.setBackgroundDrawable(ContextCompat.getDrawable(this,
                        R.drawable.last_revolut_gradient))
            } else {
                //Expanded
                toolBar.setBackgroundColor(ContextCompat.getColor(this,
                        android.R.color.transparent))
            }
        }
0
ответ дан haroldolivieri 21 August 2018 в 14:00
поделиться
0
ответ дан Olivier L. Applin 1 November 2018 в 08:05
поделиться
Другие вопросы по тегам:

Похожие вопросы: