Android 更改折叠ToolAbarLayout的背景
我想在Android 更改折叠ToolAbarLayout的背景,android,imageview,Android,Imageview,我想在CollaspingToolbarLayout中更改图像视图中的背景。以下是我试图做的: activity_main.xml <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="250dp" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBa
CollaspingToolbarLayout
中更改图像视图中的背景。以下是我试图做的:
activity_main.xml
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="@color/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/collapsingimage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:background="@drawable/teszt1"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
因此,我想加载另一个图像,而不是添加到xml文件中,我设置了ImageView的背景,但什么也没有发生。你知道怎么做吗 要更改颜色,请使用属性app:contentScrim
,我看到您正在使用颜色color/colorPrimary
:
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="@color/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
要更改颜色,请使用属性app:contentScrim
,我看到您正在使用颜色color/colorPrimary
:
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="@color/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
谢谢你的回答,但是你的代码和我的完全一样。能否告诉我,我应该如何使用app:contentScrim
?您必须正确更改颜色吗?更改app:contentScrim=的颜色我想在java代码的运行时更改。我想更改工具栏中ImageView的背景。谢谢你的回答,但是你的代码和我的完全一样。能否告诉我,我应该如何使用app:contentScrim
?您必须正确更改颜色吗?更改app:contentScrim=的颜色我想在java代码的运行时更改。我想更改工具栏内ImageView的背景。
collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
int colorPrimary = getResources().getColor(R.color.colorPrimary);
collapsingToolbarLayout.setBackgroundColor(colorPrimary);
collapsingToolbarLayout.setContentScrimColor(colorPrimary);
collapsingToolbarLayout.setStatusBarScrimColor(colorPrimary);