1、设置渐变背景

<shape xmlns:android="http://schemas.android.com/apk/res/android"

    android:shape="rectangle">

    <gradient

        android:centerColor="#1FBDFF"

        android:endColor="#1FA5FF"

        android:startColor="#02EEFF"

        android:type="linear" />

</shape>

2、设置圆角渐变按钮

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- 连框颜色值 -->

    <item>

        <shape>

            <corners android:radius="4dp" />

        </shape>

    </item>

    <!-- 主体背景颜色值 -->

    <item

        android:bottom="1dp"

        android:left="1dp"

        android:right="1dp"

        android:top="1dp">

        <shape>

            <gradient

                android:centerColor="#1FBDFF"

                android:endColor="#1FA5FF"

                android:startColor="#02EEFF"

                android:type="linear" />

            <!-- 圆角 -->

            <corners android:radius="4dp" />

        </shape>

    </item>

</layer-list>

3、TextView设置不同颜色

SpannableString receiver = new SpannableString(beanInfo.getUpdator() + "领取");

receiver.setSpan(new ForegroundColorSpan(Color.parseColor("#5B6175")), beanInfo.getUpdator().length(), beanInfo.getUpdator().length() + 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

tvReceiver.setText(receiver);

4、Android系统从9升级到10后,shape—gradient设置控件渐变,水平变成垂直

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
       <gradient
             android:centerColor="#1FBDFF"
             android:endColor="#1FA5FF"
             android:startColor="#02EEFF"
             android:type="linear"
             android:angle="0"/>//增加angle属性
</shape>

5、bitmap返回灰度图片

/**
* @return bitmap返回灰度图片
*/
public static Bitmap toGrayscale(Bitmap bmp) {
        if (bmp != null) {
            //为图片添加滤镜
            Bitmap mGrayBitmap = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Bitmap.Config.ARGB_8888);
            Canvas mCanvas = new Canvas(mGrayBitmap);
            Paint mPaint = new Paint();

            //调整色相
            ColorMatrix rotateMatrix = new ColorMatrix();
            rotateMatrix.setRotate(0, 0);
            rotateMatrix.setRotate(1, 0);
            rotateMatrix.setRotate(2, 0);

            //调整色彩饱和度
            ColorMatrix saturationMatrix = new ColorMatrix();
            saturationMatrix.setSaturation(0);

            //调整亮度
            ColorMatrix scaleMatrix = new ColorMatrix();
            scaleMatrix.setScale(0, 0, 0, 1);

            //叠加效果
            ColorMatrix colorMatrix = new ColorMatrix();
            colorMatrix.postConcat(rotateMatrix);
            colorMatrix.postConcat(saturationMatrix);
            colorMatrix.postConcat(scaleMatrix);

            //设置画笔的颜色过滤矩阵
            mPaint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
            //使用处理后的画笔绘制图像
            mCanvas.drawBitmap(bmp, 0, 0, mPaint);
            return mGrayBitmap;
        } else {
            return bmp;
        }
    }

6、ImageView设置黑白图片

    /**
     * @return ImageView设置灰度图片
     */
    public static void toGrayscale(ImageView imageView) {

        ColorMatrix colorMatrix = new ColorMatrix();
        ColorMatrix mHueMatrix = new ColorMatrix();
        ColorMatrix mSaturationMatrix = new ColorMatrix();
        ColorMatrix mLightnessMatrix = new ColorMatrix();

        //设置色相
        mHueMatrix.setRotate(0, 0);
        mHueMatrix.setRotate(1, 0);
        mHueMatrix.setRotate(2, 0);

        //设置饱和度
        mSaturationMatrix.setSaturation(0);

        //亮度
        mLightnessMatrix.setScale(0, 0, 0, 1);

        // 效果叠加
        colorMatrix.postConcat(mLightnessMatrix);
        colorMatrix.postConcat(mSaturationMatrix);
        colorMatrix.postConcat(mHueMatrix);

        imageView.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
    }

7、动态设置控件文字颜色selector不起作用

button.setTextColor(R.drawable.text_selector);

改为:
button.setTextColor(getResources().getColorStateList(R.drawable.text_selector));

 8、CoordinatorLayout,BottomSheet和RecyclerView搭配使用时滑动冲突(BottomSheet全部展开时,向下滑动不缩回)

recyclerView.setNestedScrollingEnabled(false);

 

 posted on 2019-12-04 16:36  落舒  阅读(297)  评论(0)    收藏  举报