Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 更改折叠ToolAbarLayout的背景_Android_Imageview - Fatal编程技术网

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);