目录
用到的库
1.抽屉布局:ScrollLayout
https://github.com/yingLanNull/ScrollLayout
2.状态栏自定义:
https://github.com/laobie/StatusBarUtil
Android状态栏透明、更改状态栏文字颜色
简书中超详细的解决方案:
https://www.jianshu.com/p/7392237bc1de
具体问题:
1.如何使状态栏透明?
//4.4以后能直接更改颜色
//使用SystemBarTint库使4.4版本状态栏变色,需要先将状态栏设置为透明
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = activity.getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window window = activity.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
就是这么简单
\
2.如何更改字体颜色?
需要根据不同手机型号来确定不同的更改方式
小米:
Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
darkModeFlag = field.getInt(layoutParams);
Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
//设置
if (dark) {
extraFlagField.invoke(window, darkModeFlag, darkModeFlag);//状态栏透明且黑色字体
} else {
extraFlagField.invoke(window, 0, darkModeFlag);//清除黑色字体
}
魅族
WindowManager.LayoutParams lp = window.getAttributes();
Field darkFlag = WindowManager.LayoutParams.class
.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
Field meizuFlags = WindowManager.LayoutParams.class
.getDeclaredField("meizuFlags");
darkFlag.setAccessible(true);
meizuFlags.setAccessible(true);
int bit = darkFlag.getInt(null);
int value = meizuFlags.getInt(lp);
if (dark) {
value |= bit;
} else {
value &= ~bit;
}
meizuFlags.setInt(lp, value);
window.setAttributes(lp);
谷歌原生
private static void setAndroidNativeLightStatusBar(Activity activity, boolean dark) {
View decor = activity.getWindow().getDecorView();
if (dark) {
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
} else {
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
}
}
这里有个注意点:
一旦用谷歌原生设置状态栏文字颜色的方法进行设置的话,因为一直会携带SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN这个flag,那么默认界面会变成全屏模式,需要在根布局中设置FitsSystemWindows属性为true,所以我在基类的 process方法中加入如下的代码。
@Override
protected void process(Bundle savedInstanceState) {
// 华为,OPPO机型在StatusBarUtil.setLightStatusBar后布局被顶到状态栏上去了
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
View content = ((ViewGroup) findViewById(android.R.id.content)).getChildAt(0);
if (content != null && !isUseFullScreenMode()) {
content.setFitsSystemWindows(true);
}
}
}
系统判断
// 小米系统判断
private static boolean isMiUIV6OrAbove() {
try {
final Properties properties = new Properties();
properties.load(new FileInputStream(new File(Environment.getRootDirectory(), "build.prop")));
String uiCode = properties.getProperty(KEY_MIUI_VERSION_CODE, null);
if (uiCode != null) {
int code = Integer.parseInt(uiCode);
return code >= 4;
} else {
return false;
}
} catch (final Exception e) {
return false;
}
}
// 魅族系统判断
private static boolean isFlymeV4OrAbove() {
String displayId = Build.DISPLAY;
if (!TextUtils.isEmpty(displayId) && displayId.contains("Flyme")) {
String[] displayIdArray = displayId.split(" ");
for (String temp : displayIdArray) {
//版本号4以上,形如4.x.
if (temp.matches("^[4-9]\\.(\\d+\\.)+\\S*")) {
return true;
}
}
}
return false;
}
关于华为手机裁剪出现圆形框的问题:
在intent的地方判断,只要设置比例不是1:1就行
if (Build.MANUFACTURER.equals("HUAWEI")) {
intent.putExtra("aspectX", 9998);
intent.putExtra("aspectY", 9999);
} else {
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
}
图片内存优化
可以看看这篇文章,很全面
https://www.sunofbeach.net/a/1201046779781566464
-------------------------------------------完成---------------------------------------
-------------------------------------------·---------------------------------------
百度sdk的问题
详见博文:https://blog.csdn.net/weixin_51766963/article/details/114855639
-------------------------------------------完成---------------------------------------
数据库java.lang.IllegalStateException: Couldn’t read row 0, col -1 from CursorWindow.
没有实现数据库的字段与android写的字段一致。
\
RecyclerView 子布局wrap_content无用的解决办法
LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext()) {
@Override
public RecyclerView.LayoutParams generateDefaultLayoutParams() {
return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
}
};
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);