android.support.annotation.ColorInt Java Examples

The following examples show how to use android.support.annotation.ColorInt. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StatusBarUtils.java    From tysq-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 设置状态栏颜色(5.0以下无半透明效果,不建议使用)
 *
 * @param activity 需要设置的 activity
 * @param color    状态栏颜色值
 */
@Deprecated
public static void setColorDiff(Activity activity, @ColorInt int color) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    transparentStatusBar(activity);
    ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
    // 移除半透明矩形,以免叠加
    View fakeStatusBarView = contentView.findViewById(FAKE_STATUS_BAR_VIEW_ID);
    if (fakeStatusBarView != null) {
        if (fakeStatusBarView.getVisibility() == View.GONE) {
            fakeStatusBarView.setVisibility(View.VISIBLE);
        }
        fakeStatusBarView.setBackgroundColor(color);
    } else {
        contentView.addView(createStatusBarView(activity, color));
    }
    setRootView(activity);
}
 
Example #2
Source File: StatusBarUtil.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 为DrawerLayout 布局设置状态栏变色(5.0以下无半透明效果,不建议使用)
 *
 * @param activity     需要设置的activity
 * @param drawerLayout DrawerLayout
 * @param color        状态栏颜色值
 */
@Deprecated
public static void setColorForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        // 生成一个状态栏大小的矩形
        ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
        View fakeStatusBarView = contentLayout.findViewById(FAKE_STATUS_BAR_VIEW_ID);
        if (fakeStatusBarView != null) {
            if (fakeStatusBarView.getVisibility() == View.GONE) {
                fakeStatusBarView.setVisibility(View.VISIBLE);
            }
            fakeStatusBarView.setBackgroundColor(calculateStatusColor(color, DEFAULT_STATUS_BAR_ALPHA));
        } else {
            // 添加 statusBarView 到布局中
            contentLayout.addView(createStatusBarView(activity, color), 0);
        }
        // 内容布局不是 LinearLayout 时,设置padding top
        if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
            contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
        }
        // 设置属性
        setDrawerLayoutProperty(drawerLayout, contentLayout);
    }
}
 
Example #3
Source File: StatusBarUtil.java    From FimiX8-RE with MIT License 6 votes vote down vote up
@Deprecated
public static void setColorForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) {
    if (VERSION.SDK_INT >= 19) {
        activity.getWindow().addFlags(NTLMConstants.FLAG_UNIDENTIFIED_9);
        ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
        if (contentLayout.getChildCount() <= 0 || !(contentLayout.getChildAt(0) instanceof StatusBarView)) {
            contentLayout.addView(createStatusBarView(activity, color), 0);
        } else {
            contentLayout.getChildAt(0).setBackgroundColor(calculateStatusColor(color, 0));
        }
        if (!((contentLayout instanceof LinearLayout) || contentLayout.getChildAt(1) == null)) {
            contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
        }
        setDrawerLayoutProperty(drawerLayout, contentLayout);
    }
}
 
Example #4
Source File: StatusBarUtils.java    From tysq-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 为DrawerLayout 布局设置状态栏变色(5.0以下无半透明效果,不建议使用)
 *
 * @param activity     需要设置的activity
 * @param drawerLayout DrawerLayout
 * @param color        状态栏颜色值
 */
@Deprecated
public static void setColorForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        // 生成一个状态栏大小的矩形
        ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
        View fakeStatusBarView = contentLayout.findViewById(FAKE_STATUS_BAR_VIEW_ID);
        if (fakeStatusBarView != null) {
            if (fakeStatusBarView.getVisibility() == View.GONE) {
                fakeStatusBarView.setVisibility(View.VISIBLE);
            }
            fakeStatusBarView.setBackgroundColor(calculateStatusColor(color, DEFAULT_STATUS_BAR_ALPHA));
        } else {
            // 添加 statusBarView 到布局中
            contentLayout.addView(createStatusBarView(activity, color), 0);
        }
        // 内容布局不是 LinearLayout 时,设置padding top
        if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
            contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
        }
        // 设置属性
        setDrawerLayoutProperty(drawerLayout, contentLayout);
    }
}
 
Example #5
Source File: StatusBarUtil.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @ColorInt int color, int statusBarAlpha) {
    if (VERSION.SDK_INT >= 19) {
        if (VERSION.SDK_INT >= 21) {
            activity.getWindow().addFlags(Integer.MIN_VALUE);
            activity.getWindow().clearFlags(NTLMConstants.FLAG_UNIDENTIFIED_9);
            activity.getWindow().setStatusBarColor(0);
        } else {
            activity.getWindow().addFlags(NTLMConstants.FLAG_UNIDENTIFIED_9);
        }
        ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
        if (contentLayout.getChildCount() <= 0 || !(contentLayout.getChildAt(0) instanceof StatusBarView)) {
            contentLayout.addView(createStatusBarView(activity, color), 0);
        } else {
            contentLayout.getChildAt(0).setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        }
        if (!((contentLayout instanceof LinearLayout) || contentLayout.getChildAt(1) == null)) {
            contentLayout.getChildAt(1).setPadding(contentLayout.getPaddingLeft(), getStatusBarHeight(activity) + contentLayout.getPaddingTop(), contentLayout.getPaddingRight(), contentLayout.getPaddingBottom());
        }
        setDrawerLayoutProperty(drawerLayout, contentLayout);
        addTranslucentView(activity, statusBarAlpha);
    }
}
 
Example #6
Source File: BarUtils.java    From Android-utils with Apache License 2.0 6 votes vote down vote up
/**
 * Set the status bar's color for DrawerLayout.
 * <p>DrawLayout must add {@code android:fitsSystemWindows="true"}</p>
 *
 * @param drawer        The DrawLayout.
 * @param fakeStatusBar The fake status bar view.
 * @param color         The status bar's color.
 * @param isTop         True to set DrawerLayout at the top layer, false otherwise.
 */
public static void setStatusBarColor4Drawer(@NonNull final DrawerLayout drawer,
                                            @NonNull final View fakeStatusBar,
                                            @ColorInt final int color,
                                            final boolean isTop) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
    Activity activity = getActivityByView(fakeStatusBar);
    if (activity == null) return;
    transparentStatusBar(activity);
    drawer.setFitsSystemWindows(false);
    setStatusBarColor(fakeStatusBar, color);
    for (int i = 0, count = drawer.getChildCount(); i < count; i++) {
        drawer.getChildAt(i).setFitsSystemWindows(false);
    }
    if (isTop) {
        hideStatusBarView(activity);
    } else {
        setStatusBarColor(activity, color, false);
    }
}
 
Example #7
Source File: StatusBarUtil.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 设置状态栏颜色
 *
 * @param activity       需要设置的activity
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */

public static void setColor(Activity activity, @ColorInt int color, @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(calculateStatusColor(color, statusBarAlpha));
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
        View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID);
        if (fakeStatusBarView != null) {
            if (fakeStatusBarView.getVisibility() == View.GONE) {
                fakeStatusBarView.setVisibility(View.VISIBLE);
            }
            fakeStatusBarView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        } else {
            decorView.addView(createStatusBarView(activity, color, statusBarAlpha));
        }
        setRootView(activity);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        activity.getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    }
}
 
Example #8
Source File: ImageUtils.java    From Android-utils with Apache License 2.0 5 votes vote down vote up
public static Bitmap drawColor(@NonNull final Bitmap src, @ColorInt final int color, final boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    Bitmap ret = recycle ? src : src.copy(src.getConfig(), true);
    Canvas canvas = new Canvas(ret);
    canvas.drawColor(color, PorterDuff.Mode.DARKEN);
    return ret;
}
 
Example #9
Source File: StatusBarUtil.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 计算状态栏颜色
 *
 * @param color color值
 * @param alpha alpha值
 * @return 最终的状态栏颜色
 */
private static int calculateStatusColor(@ColorInt int color, int alpha) {
    if (alpha == 0) {
        return color;
    }
    float a = 1 - alpha / 255f;
    int red = color >> 16 & 0xff;
    int green = color >> 8 & 0xff;
    int blue = color & 0xff;
    red = (int) (red * a + 0.5);
    green = (int) (green * a + 0.5);
    blue = (int) (blue * a + 0.5);
    return 0xff << 24 | red << 16 | green << 8 | blue;
}
 
Example #10
Source File: StatusBarUtil.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 生成一个和状态栏大小相同的半透明矩形条
 *
 * @param activity 需要设置的activity
 * @param color    状态栏颜色值
 * @param alpha    透明值
 * @return 状态栏矩形条
 */
private static View createStatusBarView(Activity activity, @ColorInt int color, int alpha) {
    // 绘制一个和状态栏一样高的矩形
    View statusBarView = new View(activity);
    LinearLayout.LayoutParams params =
            new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity));
    statusBarView.setLayoutParams(params);
    statusBarView.setBackgroundColor(calculateStatusColor(color, alpha));
    statusBarView.setId(FAKE_STATUS_BAR_VIEW_ID);
    return statusBarView;
}
 
Example #11
Source File: MIUIDrawer.java    From EasySwipeLayout with MIT License 5 votes vote down vote up
public void setBackgroundColor(@ColorInt int color) {
    if (mBackgroundColor != color) {
        mBackgroundColor = color;
        mBackgroundPaint.setColor(mBackgroundColor);
        requestInvalidate();
    }
}
 
Example #12
Source File: StatusBarUtils.java    From tysq-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 设置状态栏颜色
 *
 * @param activity       需要设置的activity
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */
public static void setColor(Activity activity, @ColorInt int color, @IntRange(from = 0, to = 255) int statusBarAlpha) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

        /**
         * FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS 设置的作用是为了 系统以透明的背景绘制 状态栏 和 底部导航栏
         * 同时系统会以 {@link Window#getStatusBarColor()} 和 {@link Window#getNavigationBarColor()} 进行填充
         */
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        // FLAG_TRANSLUCENT_STATUS 半透明状态栏
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        // 设置状态栏颜色,必须要设置了 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS 才有效
        activity.getWindow().setStatusBarColor(calculateStatusColor(color, statusBarAlpha));

    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
        View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID);
        if (fakeStatusBarView != null) {
            if (fakeStatusBarView.getVisibility() == View.GONE) {
                fakeStatusBarView.setVisibility(View.VISIBLE);
            }
            fakeStatusBarView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        } else {
            decorView.addView(createStatusBarView(activity, color, statusBarAlpha));
        }
        setRootView(activity);

    }

}
 
Example #13
Source File: StatusBarUtil.java    From FimiX8-RE with MIT License 5 votes vote down vote up
@Deprecated
public static void setColorDiff(Activity activity, @ColorInt int color) {
    if (VERSION.SDK_INT >= 19) {
        transparentStatusBar(activity);
        ViewGroup contentView = (ViewGroup) activity.findViewById(16908290);
        if (contentView.getChildCount() > 1) {
            contentView.getChildAt(1).setBackgroundColor(color);
        } else {
            contentView.addView(createStatusBarView(activity, color));
        }
        setRootView(activity);
    }
}
 
Example #14
Source File: StatusBarUtil.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @param activity       需要设置的activity
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */
public static void setColorForSwipeBack(Activity activity, @ColorInt int color,
                                        @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

        ViewGroup contentView = ((ViewGroup) activity.findViewById(android.R.id.content));
        View rootView = contentView.getChildAt(0);
        int statusBarHeight = getStatusBarHeight(activity);
        if (rootView != null && rootView instanceof CoordinatorLayout) {
            final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) rootView;
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                coordinatorLayout.setFitsSystemWindows(false);
                contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
                boolean isNeedRequestLayout = contentView.getPaddingTop() < statusBarHeight;
                if (isNeedRequestLayout) {
                    contentView.setPadding(0, statusBarHeight, 0, 0);
                    coordinatorLayout.post(new Runnable() {
                        @Override
                        public void run() {
                            coordinatorLayout.requestLayout();
                        }
                    });
                }
            } else {
                coordinatorLayout.setStatusBarBackgroundColor(calculateStatusColor(color, statusBarAlpha));
            }
        } else {
            contentView.setPadding(0, statusBarHeight, 0, 0);
            contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        }
        setTransparentForWindow(activity);
    }
}
 
Example #15
Source File: BarUtils.java    From Android-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Set the status bar's color.
 *
 * @param fakeStatusBar The fake status bar view.
 * @param color         The status bar's color.
 */
public static void setStatusBarColor(@NonNull final View fakeStatusBar,
                                     @ColorInt final int color) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
    Activity activity = getActivityByView(fakeStatusBar);
    if (activity == null) return;
    transparentStatusBar(activity);
    fakeStatusBar.setVisibility(View.VISIBLE);
    ViewGroup.LayoutParams layoutParams = fakeStatusBar.getLayoutParams();
    layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
    layoutParams.height = getStatusBarHeight();
    fakeStatusBar.setBackgroundColor(color);
}
 
Example #16
Source File: MIUIDrawer.java    From EasySwipeLayout with MIT License 5 votes vote down vote up
public void setArrowColor(@ColorInt int color) {
    if (mArrowColor != color) {
        mArrowColor = color;
        mArrowPaint.setColor(mArrowColor);
        requestInvalidate();
    }
}
 
Example #17
Source File: ImageUtils.java    From Android-utils with Apache License 2.0 5 votes vote down vote up
public static Bitmap toRound(final Bitmap src,
                             @IntRange(from = 0) int borderSize,
                             @ColorInt int borderColor,
                             final boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    int width = src.getWidth();
    int height = src.getHeight();
    int size = Math.min(width, height);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    Bitmap ret = Bitmap.createBitmap(width, height, src.getConfig());
    float center = size / 2f;
    RectF rectF = new RectF(0, 0, width, height);
    rectF.inset((width - size) / 2f, (height - size) / 2f);
    Matrix matrix = new Matrix();
    matrix.setTranslate(rectF.left, rectF.top);
    matrix.preScale((float) size / width, (float) size / height);
    BitmapShader shader = new BitmapShader(src, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    shader.setLocalMatrix(matrix);
    paint.setShader(shader);
    Canvas canvas = new Canvas(ret);
    canvas.drawRoundRect(rectF, center, center, paint);
    if (borderSize > 0) {
        paint.setShader(null);
        paint.setColor(borderColor);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(borderSize);
        float radius = center - borderSize / 2f;
        canvas.drawCircle(width / 2f, height / 2f, radius, paint);
    }
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
Example #18
Source File: StatusBarUtil.java    From StatusBarUtil with Apache License 2.0 5 votes vote down vote up
/**
 * 设置纯色状态栏(自定义颜色,alpha)
 *
 * @param activity 目标activity
 * @param color    状态栏颜色值
 * @param alpha    状态栏透明度
 */
public static void setColor(@NonNull Activity activity, @ColorInt int color, @IntRange(from = 0, to = 255) int alpha) {
    WeakReference<Activity> activityWeakReference = new WeakReference<>(activity);
    Window window = activityWeakReference.get().getWindow();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(cipherColor(color, alpha));
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        setTranslucentView((ViewGroup) window.getDecorView(), color, alpha);
        setRootView(activityWeakReference.get(), true);
    }
}
 
Example #19
Source File: ColorUtils.java    From Android-utils with Apache License 2.0 5 votes vote down vote up
/**
 * 获得颜色 ARGB 各个纬度的分量
 *
 * @param color 颜色
 * @return      ARGB 各个分量组成的数组
 */
public static int[] getColorARGB(@ColorInt int color) {
    int[] argb = new int[4];
    argb[0] = Color.alpha(color);
    argb[1] = Color.red(color);
    argb[2] = Color.green(color);
    argb[3] = Color.blue(color);
    return argb;
}
 
Example #20
Source File: ImageUtils.java    From Android-utils with Apache License 2.0 5 votes vote down vote up
public static Bitmap toRoundCorner(final Bitmap src,
                                   final float radius,
                                   @IntRange(from = 0) int borderSize,
                                   @ColorInt int borderColor,
                                   final boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    int width = src.getWidth();
    int height = src.getHeight();
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    Bitmap ret = Bitmap.createBitmap(width, height, src.getConfig());
    BitmapShader shader = new BitmapShader(src, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    paint.setShader(shader);
    Canvas canvas = new Canvas(ret);
    RectF rectF = new RectF(0, 0, width, height);
    float halfBorderSize = borderSize / 2f;
    rectF.inset(halfBorderSize, halfBorderSize);
    canvas.drawRoundRect(rectF, radius, radius, paint);
    if (borderSize > 0) {
        paint.setShader(null);
        paint.setColor(borderColor);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(borderSize);
        paint.setStrokeCap(Paint.Cap.ROUND);
        canvas.drawRoundRect(rectF, radius, radius, paint);
    }
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
Example #21
Source File: ImageUtils.java    From Android-utils with Apache License 2.0 5 votes vote down vote up
public static Bitmap addCornerBorder(final Bitmap src,
                                     @IntRange(from = 1) final int borderSize,
                                     @ColorInt final int color,
                                     @FloatRange(from = 0) final float cornerRadius,
                                     final boolean recycle) {
    return addBorder(src, borderSize, color, false, cornerRadius, recycle);
}
 
Example #22
Source File: RTCCall.java    From meshenger-android with GNU General Public License v3.0 5 votes vote down vote up
private void setRemoteVideoEnabled(boolean enabled) {
    new Handler(Looper.getMainLooper()).post(() -> {
        if (enabled) {
            this.remoteRenderer.setBackgroundColor(Color.TRANSPARENT);
        } else {
            TypedValue typedValue = new TypedValue();
            Resources.Theme theme = this.context.getTheme();
            theme.resolveAttribute(R.attr.backgroundCardColor, typedValue, true);
            @ColorInt int color = typedValue.data;
            this.remoteRenderer.setBackgroundColor(color);
        }
    });
}
 
Example #23
Source File: StatusBarUtils.java    From tysq-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 为DrawerLayout 布局设置状态栏变色
 *
 * @param activity       需要设置的activity
 * @param drawerLayout   DrawerLayout
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */
public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @ColorInt int color,
                                           @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
    // 生成一个状态栏大小的矩形
    // 添加 statusBarView 到布局中
    ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
    View fakeStatusBarView = contentLayout.findViewById(FAKE_STATUS_BAR_VIEW_ID);
    if (fakeStatusBarView != null) {
        if (fakeStatusBarView.getVisibility() == View.GONE) {
            fakeStatusBarView.setVisibility(View.VISIBLE);
        }
        fakeStatusBarView.setBackgroundColor(color);
    } else {
        contentLayout.addView(createStatusBarView(activity, color), 0);
    }
    // 内容布局不是 LinearLayout 时,设置padding top
    if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
        contentLayout.getChildAt(1)
                .setPadding(contentLayout.getPaddingLeft(), getStatusBarHeight(activity) + contentLayout.getPaddingTop(),
                        contentLayout.getPaddingRight(), contentLayout.getPaddingBottom());
    }
    // 设置属性
    setDrawerLayoutProperty(drawerLayout, contentLayout);
    addTranslucentView(activity, statusBarAlpha);
}
 
Example #24
Source File: ImageUtils.java    From Android-utils with Apache License 2.0 5 votes vote down vote up
public static Bitmap addTextWatermark(final Bitmap src,
                                      final String content,
                                      final int textSize,
                                      @ColorInt final int color,
                                      final float x,
                                      final float y) {
    return addTextWatermark(src, content, textSize, color, x, y, false);
}
 
Example #25
Source File: ImageUtils.java    From Android-utils with Apache License 2.0 4 votes vote down vote up
public static Bitmap addCircleBorder(final Bitmap src,
                                     @IntRange(from = 1) final int borderSize,
                                     @ColorInt final int color) {
    return addBorder(src, borderSize, color, true, 0, false);
}
 
Example #26
Source File: ResUtils.java    From Android-utils with Apache License 2.0 4 votes vote down vote up
@ColorInt
public static int getColor(@ColorRes int id) {
    return UtilsApp.getApp().getResources().getColor(id);
}
 
Example #27
Source File: BaseItemAdapter.java    From SimpleAdapterDemo with Apache License 2.0 4 votes vote down vote up
public BaseItemViewHolder setBackgroundColor(@IdRes int id, @ColorInt int color) {
    View view = findViewById(id);
    if (view != null)
        view.setBackgroundColor(color);
    return this;
}
 
Example #28
Source File: BaseItemAdapter.java    From SimpleAdapterDemo with Apache License 2.0 4 votes vote down vote up
public BaseItemViewHolder setTextColor(@IdRes int id, @ColorInt int color) {
    View view = findViewById(id);
    if (view instanceof TextView)
        ((TextView) view).setTextColor(color);
    return this;
}
 
Example #29
Source File: BaseHeaderFooterAdapter.java    From SimpleAdapterDemo with Apache License 2.0 4 votes vote down vote up
public BaseViewHolder setBackgroundColor(@IdRes int id, @ColorInt int color) {
    View view = findViewById(id);
    if (view != null)
        view.setBackgroundColor(color);
    return this;
}
 
Example #30
Source File: BaseHeaderFooterAdapter.java    From SimpleAdapterDemo with Apache License 2.0 4 votes vote down vote up
public BaseViewHolder setTextColor(@IdRes int id, @ColorInt int color) {
    View view = findViewById(id);
    if (view instanceof TextView)
        ((TextView) view).setTextColor(color);
    return this;
}