小编Roe*_*oee的帖子

CollapsingToolBarLayout - 状态栏稀松布颜色不会更改

我几天前更新了我的android工作室,并开始使用CoordinatorLayout和CollapsingToolbarLayout尝试的东西.

似乎工具栏稀松布颜色覆盖状态栏初始颜色和状态栏稀松布颜色(从xml和代码尝试)

初始状态:

初始状态:


开始滚动:

开始滚动


滚动直至折叠:

滚动直到折叠


所以问题是:

  1. 如何在折叠时阻止工具栏覆盖状态栏(甚至不让我正在折叠的图像超过它).

  2. 如何在折叠后更改状态栏颜色

我遇到的另一个问题是我给了工具栏的初始颜色而不仅仅是稀松布颜色,因为我希望工具栏位于图片上方,而是它会在图片的顶部显示,并覆盖其中的一些,并覆盖任何内容.落后于它


为xml中的工具栏添加了颜色/样式:

为xml中的工具栏添加了颜色/样式


  1. 有没有办法将工具栏从头开始放在图片上方,只是折叠图像?(考虑可能保持工具栏固定和框架布局在图像之前,但它仍然会在状态栏区域崩溃,这是主要问题.)

主要活动xml:

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:contentScrim = "?attr/colorPrimary"
        app:statusBarScrim="?attr/colorAccent" --------> not changing
        android:id="@+id/my_ctl">


        <ImageView
            android:id="@+id/image"
            android:src="@drawable/flights"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:scaleType="centerCrop"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax"
            />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:layout_collapseMode="pin" />


    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>


<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" >

    <include layout="@layout/content_main" />

</android.support.v4.widget.NestedScrollView>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

MainActivity.java:

  CollapsingToolbarLayout ctl = (CollapsingToolbarLayout) findViewById(R.id.my_ctl);
    //ctl.setContentScrimColor(Color.RED);
    ctl.setStatusBarScrimColor(Color.BLUE);  --------> not working
    ctl.setTitle("blabla");
Run Code Online (Sandbox Code Playgroud)

android android-toolbar android-collapsingtoolbarlayout android-6.0-marshmallow

24
推荐指数
2
解决办法
2万
查看次数

Bitmap.compress - 不起作用

我正在尝试压缩用相机拍摄的照片而不缩放图像尺寸。

我尝试了 bitmap.compress,但没有成功。只是为了确保我尝试压缩从资源加载的位图,但仍然没有成功。

有任何想法吗?

示例代码:

//load bitmap from resources:
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.trolltunga);
Log.d("roee", "onImageCaptured: before compress = " + bitmap.getByteCount() + ", " + bitmap.getWidth() + ", " + bitmap.getHeight());

//compressing
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, bos);
Bitmap comp = BitmapFactory.decodeStream(new ByteArrayInputStream(bos.toByteArray()));
Log.d("roee", "onImageCaptured: after compress = " + comp.getByteCount() + ", " + comp.getWidth() + ", " + comp.getHeight());
Run Code Online (Sandbox Code Playgroud)

记录结果:

D/roee: onImageCaptured: before compress = 10800000, 3000, 900
D/roee: onImageCaptured: after compress = 10800000, 3000, 900
Run Code Online (Sandbox Code Playgroud)

java compression android bitmap image-compression

3
推荐指数
1
解决办法
4166
查看次数