package com.example.saomademo.utils;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import com.example.saomademo.R;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import java.lang.reflect.Field;
import static com.example.saomademo.utils.StatusBarUtils.getStatusBarHeight;
/**
* <pre>
* @author yangchong
* blog : https://github.com/yangchong211/YCStatusBar
* time : 2018/06/4
* desc : 状态栏工具类
* revise: 使用方法请看GitHub说明文档
* </pre>
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
final class BarStatusKitKat {
private static final String TAG_FAKE_STATUS_BAR_VIEW = "statusBarView";
private static final String TAG_MARGIN_ADDED = "marginAdded";
static void setStatusBarColor(Activity activity, int statusColor) {
Window window = activity.getWindow();
//设置Window为全透明
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
//获取父布局
View mContentChild = mContentView.getChildAt(0);
//获取状态栏高度
int statusBarHeight = getStatusBarHeight(activity);
//如果已经存在假状态栏则移除,防止重复添加
removeFakeStatusBarViewIfExist(activity);
//添加一个View来作为状态栏的填充
addFakeStatusBarView(activity, statusColor, statusBarHeight);
//设置子控件到状态栏的间距
addMarginTopToContentChild(mContentChild, statusBarHeight);
//不预留系统栏位置
if (mContentChild != null) {
mContentChild.setFitsSystemWindows(false);
}
//如果在Activity中使用了ActionBar则需要再将布局与状态栏的高度跳高一个ActionBar的高度,否则内容会被ActionBar遮挡
int actionBarId = activity.getResources().getIdentifier("action_bar", "id",
activity.getPackageName());
View view = activity.findViewById(actionBarId);
if (view != null) {
TypedValue typedValue = new TypedValue();
if (activity.getTheme().resolveAttribute(R.attr.actionBarSize, typedValue, true)) {
int actionBarHeight = TypedValue.complexToDimensionPixelSize(typedValue.data, activity.getResources().getDisplayMetrics());
StateAppBar.setContentTopPadding(activity, actionBarHeight);
}
}
}
static void translucentStatusBar(Activity activity) {
Window window = activity.getWindow();
//设置Window为透明
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
ViewGroup mContentView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT);
View mContentChild = mContentView.getChildAt(0);
//移除已经存在假状态栏则,并且取消它的Margin间距
removeFakeStatusBarViewIfExist(activity);
removeMarginTopOfContentChild(mContentChild, getStatusBarHeight(activity));
if (mContentChild != null) {
//fitsSystemWindow 为 false, 不预留系统栏位置.
mContentChild.setFitsSystemWindows(false);
}
}
static void setStatusBarColorForCollapsingToolbar(final Activity activity, final AppBarLayout appBarLayout, final CollapsingToolbarLayout collapsingToolbarLayout,
Toolbar toolbar, int statusColor) {
Window window = activity.getWindow();
//设置Window为全透明
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
//AppBarLayout,CollapsingToolbarLayout,ToolBar,ImageView的fitsSystemWindow统一改为false, 不预留系统栏位置.
View mContentChild = mContentView.getChildAt(0);
mContentChild.setFitsSystemWindows(false);
((View) appBarLayout.getParent()).setFitsSystemWindows(false);
appBarLayout.setFitsSystemWindows(false);
collapsingToolbarLayout.setFitsSystemWindows(false);
collapsingToolbarLayout.getChildAt(0).setFitsSystemWindows(false);
toolbar.setFitsSystemWindows(false);
//为Toolbar添加一个状态栏的高度, 同时为Toolbar添加paddingTop,使Toolbar覆盖状态栏,ToolBar的title可以正常显示.
if (toolbar.getTag() == null) {
CollapsingToolbarLayout.LayoutParams lp = (CollapsingToolbarLayout.LayoutParams) toolbar.getLayoutParams();
int statusBarHeight = getStatusBarHeight(activity);
lp.height += statusBarHeight;
toolbar.setLayoutParams(lp);
toolbar.setPadding(toolbar.getPaddingLeft(), toolbar.getPaddingTop() + statusBarHeight, toolbar.getPaddingRight(), toolbar.getPaddingBottom());
toolbar.setTag(true);
}
//移除已经存在假状态栏则,并且取消它的Margin间距
int statusBarHeight = getStatusBarHeight(activity);
removeFakeStatusBarViewIfExist(activity);
removeMarginTopOfContentChild(mContentChild, statusBarHeight);
//添加一个View来作为状态栏的填充
final View statusView = addFakeStatusBarView(activity, statusColor, statusBarHeight);
CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams()).getBehavior();
if (behavior != null && behavior instanceof AppBarLayout.Behavior) {
int verticalOffset = ((AppBarLayout.Behavior) behavior).getTopAndBottomOffset();
if (Math.abs(verticalOffset) > appBarLayout.getHeight() - collapsingToolbarLayout.getScrimVisibleHeightTrigger()) {
statusView.setAlpha(1f);
} else {
statusView.setAlpha(0f);
}
} else {
statusView.setAlpha(0f);
}
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
if (Math.abs(verticalOffset) > appBarLayout.getHeight() - collapsingToolbarLayout.getScrimVisibleHeightTrigger()) {
//toolbar被折叠时显示状态栏
if (statusView.getAlpha() == 0) {
statusView.animate().cancel();
statusView.animate().alpha(1f).setDuration(collapsingToolbarLayout.getScrimAnimationDuration()).start();
}
} else {
//toolbar展开时显示状态栏
if (statusView.getAlpha() == 1) {
statusView.animate().cancel();
statusView.animate().alpha(0f).setDuration(collapsingToolbarLayout.getScrimAnimationDuration()).start();
}
}
}
});
}
static void setStatusBarWhiteForCollapsingToolbar(final Activity activity, AppBarLayout appBarLayout, final CollapsingToolbarLayout collapsingToolbarLayout, Toolbar toolbar, final int statusBarColor) {
final Window window = activity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
View mContentChild = mContentView.getChildAt(0);
mContentChild.setFits
没有合适的资源?快使用搜索试试~ 我知道了~
Android开发 二维码扫描,识别相册图片二维码
共119个文件
xml:65个
bin:10个
java:10个
5星 · 超过95%的资源 需积分: 45 7 下载量 96 浏览量
2022-10-15
16:36:00
上传
评论
收藏 410KB RAR 举报
温馨提示
Android开发 二维码扫描,识别相册图片二维码,以及设置状态栏颜色
资源详情
资源评论
资源推荐
收起资源包目录
Android开发 二维码扫描,识别相册图片二维码 (119个子文件)
gradlew.bat 2KB
executionHistory.bin 1.56MB
classAnalysis.bin 198KB
outputFiles.bin 94KB
jarAnalysis.bin 94KB
fileHashes.bin 74KB
taskHistory.bin 30KB
sha1-checksums.bin 22KB
md5-checksums.bin 19KB
resourceHashesCache.bin 18KB
last-build.bin 1B
.gitignore 240B
.gitignore 50B
.gitignore 6B
build.gradle 1KB
build.gradle 637B
settings.gradle 48B
gradlew 5KB
saomademo.app.iml 9KB
saomademo.iml 1KB
gradle-wrapper.jar 53KB
BarStatusKitKat.java 14KB
BarStatusLollipop.java 12KB
StateAppBar.java 9KB
LgqLogPlus.java 6KB
MainActivity.java 5KB
StatusBarUtils.java 4KB
BitmapUtil.java 4KB
RGBLuminanceSource.java 3KB
ExampleInstrumentedTest.java 781B
ExampleUnitTest.java 398B
buildOutputCleanup.lock 17B
javaCompile.lock 17B
checksums.lock 17B
fileHashes.lock 17B
executionHistory.lock 17B
ic_launcher_round.png 16KB
ic_launcher_round.png 12KB
ic_launcher.png 10KB
ic_launcher.png 8KB
ic_launcher_round.png 7KB
ic_launcher_round.png 5KB
ic_launcher.png 5KB
ic_launcher.png 4KB
ic_launcher_round.png 3KB
ic_launcher.png 3KB
proguard-rules.pro 770B
gradle.properties 1019B
local.properties 419B
gradle-wrapper.properties 238B
cache.properties 53B
gc.properties 0B
gc.properties 0B
gc.properties 0B
workspace.xml 7KB
ic_launcher_background.xml 6KB
ic_launcher_foreground.xml 2KB
jarRepositories.xml 1KB
AndroidManifest.xml 1KB
Gradle__androidx_test_espresso_espresso_idling_resource_3_3_0_aar.xml 1KB
Gradle__androidx_coordinatorlayout_coordinatorlayout_1_1_0_aar.xml 1KB
Gradle__androidx_test_espresso_espresso_core_3_3_0_aar.xml 1KB
Gradle__androidx_recyclerview_recyclerview_1_1_0_aar.xml 1023B
Gradle__androidx_drawerlayout_drawerlayout_1_0_0_aar.xml 1023B
Gradle__com_google_android_material_material_1_2_1_aar.xml 1007B
Gradle__androidx_viewpager2_viewpager2_1_0_0_aar.xml 1005B
Gradle__androidx_transition_transition_1_2_0_aar.xml 1005B
Gradle__androidx_appcompat_appcompat_1_2_0_aar.xml 996B
Gradle__androidx_fragment_fragment_1_1_0_aar.xml 987B
Gradle__androidx_test_monitor_1_3_0_aar.xml 976B
Gradle__androidx_test_ext_junit_1_1_2_aar.xml 972B
Gradle__androidx_test_runner_1_3_0_aar.xml 968B
Gradle__androidx_test_core_1_3_0_aar.xml 952B
Gradle__androidx_core_core_1_3_1_aar.xml 951B
Gradle__androidx_vectordrawable_vectordrawable_animated_1_1_0_aar.xml 906B
Gradle__androidx_annotation_annotation_experimental_1_0_0_aar.xml 898B
Gradle__androidx_lifecycle_lifecycle_livedata_core_2_0_0_aar.xml 896B
Gradle__androidx_versionedparcelable_versionedparcelable_1_1_0_aar.xml 892B
Gradle__androidx_appcompat_appcompat_resources_1_2_0_aar.xml 872B
Gradle__androidx_lifecycle_lifecycle_viewmodel_2_1_0_aar.xml 872B
Gradle__androidx_lifecycle_lifecycle_livedata_2_0_0_aar.xml 866B
Gradle__androidx_lifecycle_lifecycle_runtime_2_1_0_aar.xml 860B
Gradle__androidx_vectordrawable_vectordrawable_1_1_0_aar.xml 852B
themes.xml 846B
themes.xml 846B
Gradle__androidx_cursoradapter_cursoradapter_1_0_0_aar.xml 844B
Gradle__androidx_interpolator_interpolator_1_0_0_aar.xml 836B
activity_main.xml 830B
Gradle__androidx_arch_core_core_runtime_2_0_0_aar.xml 830B
Gradle__androidx_savedstate_savedstate_1_0_0_aar.xml 820B
Gradle__androidx_customview_customview_1_0_0_aar.xml 820B
Gradle__androidx_viewpager_viewpager_1_0_0_aar.xml 812B
Gradle__androidx_activity_activity_1_0_0_aar.xml 804B
Gradle__androidx_cardview_cardview_1_0_0_aar.xml 804B
Gradle__org_hamcrest_hamcrest_integration_1_3.xml 789B
Gradle__androidx_loader_loader_1_0_0_aar.xml 788B
Gradle__androidx_annotation_annotation_1_1_0.xml 761B
Gradle__org_hamcrest_hamcrest_library_1_3.xml 760B
Gradle__org_hamcrest_hamcrest_core_1_3.xml 740B
Gradle__com_squareup_javawriter_2_1_1.xml 733B
共 119 条
- 1
- 2
meixi_android
- 粉丝: 290
- 资源: 105
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论10