niorgai / statusbarcompat Goto Github PK
View Code? Open in Web Editor NEWStatus Bar Utils ---- Change Status Bar Mode Simply
Home Page: http://niorgai.github.io/2016/03/20/Android-transulcent-status-bar/
License: MIT License
Status Bar Utils ---- Change Status Bar Mode Simply
Home Page: http://niorgai.github.io/2016/03/20/Android-transulcent-status-bar/
License: MIT License
在 Style 文件中设置 <item name="android:windowLightStatusBar">true</item>
,然后在 Activity 中使用本库提供的方法设置状态栏透明。会导致状态栏文字并不能显示为黑色,任然显示为修改前的白色
LeakCanary reports sAnimator leaking window in startColorAnimation. This could probably be fixed by using a WeakReference to access window or by cancelling the Animator when the corresponding activity is being destroyed.
如何在不同fragment下设置状态栏颜色,只有一个activity一个fragment设置了之后其他的也都被设置成一样了
Library的这个默认为false应该比较好。
miui 5.1和CM 6.0下都测试过..
Activity
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StatusBarCompat.setStatusBarColor(this,getResources().getColor(R.color.colorPrimary2));
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/mytopbar_layout" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:text="ThinkCool" />
</LinearLayout>
mytopbar_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary2"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/top_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/back" />
<TextView
android:id="@+id/top_center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="登陆"
android:textSize="16sp" />
<ImageView
android:id="@+id/top_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/add" />
</LinearLayout>
@niorgai
关于transparent模式键盘不弹,作者有好的实践方案没有
机型 oppor7s
在TabActivity下状态栏底部也会有一条黑线
bug:CollapsingFragment 在 5.1 系统中,布局会撑上去状态栏,4.4 就没问题的。
经过测试,发现以下 2 个方法,都可以解决:
1、在 MainActivity 的根布局加上 android:fitsSystemWindows="true" 可以修复这个问题;
2、不改动代码,只将项目中的兼容库版本 supportVersion : "24.2.1" ,升级为最新的 25.1.0 ,也修复了。
运行示例代码,小米 4 MIUI 8.7.10.26 在 Translucent 界面点击 Toogle 按钮后顶部状态栏没有任何变化。
朋友的小米手机也有同样的问题,机型系统未知。
StatusBarCompat.translucentStatusBar(this, true); 设置了这个后 状态栏变成了纯白色
I have a problem when using the translucent status bar inside a fragment.
What happens is that the toolbar (its title, icons and layout) goes underneath the status bar. The theme of the app is the following:
<style name="OneManStudioTheme" parent="BaseTheme">
</style>
<!-- base app theme -->
<style name="BaseTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
<item name="colorPrimary">@color/blue_picton</item>
<item name="colorPrimaryDark">@color/blue_cerulean</item>
<item name="colorAccent">@color/pink_hot</item>
</style>
I have also tried with
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
inside the OneManStudioTheme but it has no effect :(
Any ideas what might be wrong?
Have you tested your library with the new Theme.MaterialComponents.Light.NoActionBar family of themes?
Any help would be greatly appreciated :)
小米的mix2 上面测试不好用,最新发现的,求大神指点
状态栏白色 状态栏文字显示为白色
加了 StatusBarCompat.translucentStatusBar(activity) 之后,在4.4+完美显示,但是在5.0上状态栏是灰色的,不是黑色的,也不是透明的 布局使用了
CoordinatorLayout
AppBarLayout
CollapsingToolbarLayout
Toolbar
> Manifest merger failed : Attribute application@label value=(@string/label_application) from AndroidManifest.xml:16:7-48
is also present at [com.github.niorgai:StatusBarCompat:2.1.3] AndroidManifest.xml:13:9-41 value=(@string/app_name).
Suggestion: add 'tools:replace="android:label"' to <application> element at AndroidManifest.xml:6:3-8:37 to override.```
华为手机设置状态栏颜色无效。求解决方案
lib的minSdk是15,我的项目minSdk是14,我的版本不能提高,要如何处理啊?
如题
设置 StatusBarCompat.translucentStatusBar(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
StatusBarCompat.translucentStatusBar(this, true);
} 的时候 adjustResize 属性正常,设置后属性失效
Error:(25, 13) Failed to resolve: com.github.niorgai:StatusBarCompat:1.1.0
Show in File
Show in Project Structure dialog
我最近在做一个需求,状态栏黑色字体(只是android6以上即可),但是我设置了后,就无法侵入状态栏了
异常日志:
06-17 19:42:08.612 E/AndroidRuntime(18651): Process: com.yanshiv8.huosuapp, PID: 18651 06-17 19:42:08.612 E/AndroidRuntime(18651): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.yanshiv8.huosuapp/com.etsdk.game.ui.game.details.NewGameDetailsActivity}: java.lang.NullPointerException 06-17 19:42:08.612 E/AndroidRuntime(18651): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2429) 06-17 19:42:08.612 E/AndroidRuntime(18651): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493) 06-17 19:42:08.612 E/AndroidRuntime(18651): at android.app.ActivityThread.access$800(ActivityThread.java:166) 06-17 19:42:08.612 E/AndroidRuntime(18651): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283) 06-17 19:42:08.612 E/AndroidRuntime(18651): at android.os.Handler.dispatchMessage(Handler.java:102) 06-17 19:42:08.612 E/AndroidRuntime(18651): at android.os.Looper.loop(Looper.java:136) 06-17 19:42:08.612 E/AndroidRuntime(18651): at android.app.ActivityThread.main(ActivityThread.java:5584) 06-17 19:42:08.612 E/AndroidRuntime(18651): at java.lang.reflect.Method.invokeNative(Native Method) 06-17 19:42:08.612 E/AndroidRuntime(18651): at java.lang.reflect.Method.invoke(Method.java:515) 06-17 19:42:08.612 E/AndroidRuntime(18651): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) 06-17 19:42:08.612 E/AndroidRuntime(18651): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) 06-17 19:42:08.612 E/AndroidRuntime(18651): at dalvik.system.NativeStart.main(Native Method) 06-17 19:42:08.612 E/AndroidRuntime(18651): Caused by: java.lang.NullPointerException 06-17 19:42:08.612 E/AndroidRuntime(18651): at qiu.niorgai.StatusBarCompatKitKat.translucentStatusBar(StatusBarCompatKitKat.java:142) 06-17 19:42:08.612 E/AndroidRuntime(18651): at qiu.niorgai.StatusBarCompat.translucentStatusBar(StatusBarCompat.java:58) 06-17 19:42:08.612 E/AndroidRuntime(18651): at com.etsdk.game.base.BaseActivity.setContentView(BaseActivity.java:191) 06-17 19:42:08.612 E/AndroidRuntime(18651): at com.etsdk.game.ui.game.details.NewGameDetailsActivity.onCreate(NewGameDetailsActivity.java:98) 06-17 19:42:08.612 E/AndroidRuntime(18651): at android.app.Activity.performCreate(Activity.java:5442) 06-17 19:42:08.612 E/AndroidRuntime(18651): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) 06-17 19:42:08.612 E/AndroidRuntime(18651): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393) 06-17 19:42:08.612 E/AndroidRuntime(18651): ... 11 more
这上面的报错的行数不对,我查看了下smali文件,报错代码:
具体对应代码
static void translucentStatusBar(Activity activity) { Window window = activity.getWindow(); window.addFlags(67108864); ViewGroup mContentView = (ViewGroup)activity.findViewById(16908290); //此处mContentView可能为null,导致崩溃 View mContentChild = mContentView.getChildAt(0); removeFakeStatusBarViewIfExist(activity); removeMarginTopOfContentChild(mContentChild, getStatusBarHeight(activity)); if (mContentChild != null) { ViewCompat.setFitsSystemWindows(mContentChild, false); } }
状态栏渐变色怎么弄
调用translucentStatusBar(Activity activity, boolean hideStatusBarBackground),后面的参数传true,在api
21上面,状态栏变成白色
collapsingToolbar 如果快速话动几次,状态栏的颜色就乱了,展开的时候状态变成了黄颜色, 折叠后状态栏变成和toolbar一样的蓝色
能不能把清单文件中的application的两个属性android:allowBackup="true"和android:supportsRtl="true"去掉,与我项目中的合并冲突了。
Error: Attribute application@allowBackup value=(false) from AndroidManifest.xml:20:9-36 is also present at [com.github.niorgai:StatusBarCompat:2.1.4] AndroidManifest.xml:12:9-35 value=(true). Suggestion: add 'tools:replace="android:allowBackup"' to <application> element at AndroidManifest.xml:18:5-412:19 to override.
StatusBarCompat.setStatusBarColorForCollapsingToolbar用这个方法的时候,会报
android.widget.FrameLayout$LayoutParams cannot be cast to android.support.design.widget.CollapsingToolbarLayout$LayoutParams 强制转换的错误,实在是不懂啊
实例这种同一个activity,不同的fragment,当在一个fragment A中调用:
@OverRide
public void onHiddenChanged(boolean hidden) {
super.onHiddenChanged(hidden);
if (!hidden) {
StatusBarCompat.setStatusBarColorForCollapsingToolbar(getActivity(), mAppBarLayout, mCollapsingToolbarLayout, mToolbar, Color.TRANSPARENT);
}
}
然后在另一个fragment B中调用:
@OverRide
public void onHiddenChanged(boolean hidden) {
super.onHiddenChanged(hidden);
if (!hidden) {
StatusBarCompat.setStatusBarColor(getActivity(), getActivity().getResources().getColor(R.color.primary));
}
}
当点击底部tab显示fragment A后再点击底部tab显示fragment B后,状态栏的颜色并不是primary而是透明的。
StatusBarCompat.translucentStatusBar(this, true); 键盘 弹不上去了
有没有研究过改变状态栏文字图标颜色的方法,我现在只支持6.0以上深色模式
apptheme里增加<item name="android:windowIsTranslucent">true</item>
后,动画有变
是为标题设置一个顶部的padding吗
add library
// Before AndroidX
compile ('com.github.niorgai:StatusBarCompat:2.1.4', {
exclude group: 'com.android.support'
})
changeToLightStatusBar and cancelLightStatusBar methods not found in StatusBarCompat
我现在的app标题栏是白色的,状态栏的文字看不到了,需要设置状态的文字颜色为黑色,如何实现?
Thanks for remind.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.