laobie / statusbarutil Goto Github PK
View Code? Open in Web Editor NEWA util for setting status bar style on Android App.
Home Page: http://t.cn/Rq746Kb
License: Apache License 2.0
A util for setting status bar style on Android App.
Home Page: http://t.cn/Rq746Kb
License: Apache License 2.0
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/id_drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<com.zhy.autolayout.AutoLinearLayout
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.zhy.autolayout.AutoRelativeLayout
android:layout_width="match_parent"
android:layout_height="108px"
android:background="@color/white">
<com.zhy.autolayout.AutoLinearLayout
android:id="@+id/btn_siding"
android:layout_width="72px"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center_vertical">
<Button
android:layout_width="38px"
android:layout_height="39px"
android:background="@drawable/personal"
android:onClick="OpenLeftMenu"
android:layout_marginStart="10dp"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
</com.zhy.autolayout.AutoLinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="36px"
android:text="@string/home_title"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</com.zhy.autolayout.AutoRelativeLayout>
<include layout="@layout/activity_bottom"/>
<FrameLayout
android:id="@+id/home_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
</FrameLayout>
</com.zhy.autolayout.AutoLinearLayout>
<fragment
android:id="@+id/id_left_menu"
android:name="com.bagevent.home.fragment.MenuLeftFragment"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:tag="LEFT" />
</android.support.v4.widget.DrawerLayout>
<?xml version="1.0" encoding="utf-8"?> <FrameLayout android:id="@+id/fl" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v4.view.ViewPager android:id="@+id/vPager" android:layout_width="match_parent" android:layout_height="match_parent" /> <include layout="@layout/include_toolbar"/> </FrameLayout>
这是我的查看大图界面布局,viewpager里是包含photoview的fragment,我用StatusBarUtil.setTransparent(this);
用Fragment替换DrawerLayout下的content和drawer时,如果下面是FrameLayout就没办法换颜色,需替换成LinearLayout才能变色
像下面这样才行,如果是FrameLayout或RelativeLayout就会错乱
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:fitsSystemWindows="true">
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
<LinearLayout
android:id="@+id/drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical" />
</android.support.v4.widget.DrawerLayout>
下面函数只做了LinearLayout的判断,木有FrameLayout等的判断
public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, int color, int statusBarAlpha)
.....
// 内容布局不是 LinearLayout 时,设置padding top
if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
}
.....
如题,当我这个View快速向下滑动会出现异常 如果慢慢往下滑则不会 请猴子大神帮忙看看
scrollableLayout.setOnScrollListener(new ScrollableLayout.OnScrollListener() {
@Override
public void onScroll(int currentY, int maxY) {
if (currentY > mHeight / 1.5) {
if (isTransparent) {
isTransparent = false;
StatusBarUtil.setColor(activity, ContextCompat.getColor(activity, R.color.common_red));
rlTitleBar.setBackgroundColor(ContextCompat.getColor(activity, R.color.common_red));
}
} else {
if (!isTransparent) {
isTransparent = true;
StatusBarUtil.setTransparentForImageViewInFragment(activity, null);
rlTitleBar.setBackgroundColor(ContextCompat.getColor(activity, R.color.transparent));
}
}
}
});
异常信息:
java.lang.NullPointerException
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3072)
at android.view.View.getDisplayList(View.java:13311)
at android.view.View.getDisplayList(View.java:13415)
at android.view.HardwareRenderer$GlRenderer.buildDisplayList(HardwareRenderer.java:1570)
at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1449)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2427)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2299)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1929)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1046)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5655)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5052)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)
ImageFrament不放在viewpager的第一页时,切换到ImageFrament时整个界面往上移动了一个状态栏高度(底部冒出一个高度为状态栏高度的白色的view)。添加fragment代码如下:
mFragmentList.add(new SimpleFragment());
mFragmentList.add(new ImageFragment());
mFragmentList.add(new SimpleFragment());
mFragmentList.add(new SimpleFragment());
并且UseInFragmentActivity的setStatusBar方法改为如下:
protected void setStatusBar() {
StatusBarUtil.setColor(UseInFragmentActivity.this, ContextCompat.getColor(this, R.color.colorAccent), 0);
//isFullScreen = true;
//StatusBarUtil.setTranslucentForImageViewInFragment(UseInFragmentActivity.this,0, null);
}
其他代码未变动。
大圣,在Fragmen内使用StatusBarUtil案例中,底部菜单栏所使用的是一个第三方库(bottom-navigation-bar),有源码地址吗?请告知
如题,怎么解决?
Caused by: java.lang.NullPointerException
at com.jaeger.library.StatusBarUtil.setRootView(StatusBarUtil.java:416)
at com.jaeger.library.StatusBarUtil.setColor(StatusBarUtil.java:56)
at com.jaeger.library.StatusBarUtil.setColor(StatusBarUtil.java:31)
ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
rootView 空指针,不知道是不是魅族手机改变了根布局id
首页用的图片,其他三个fragment用的颜色,发现切换到其他界面后在切回首页,图片有部分会被不见掉。debug看了一下,第一次进来,调用clearPreviousSetting方法时,不会调用以下代码
if (count > 0 && decorView.getChildAt(count - 1) instanceof StatusBarView) {
decorView.removeViewAt(count - 1);
ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
rootView.setPadding(0, -getStatusBarHeight(activity), 0, 0);
}
所以显示正常。
切换到其他界面在切回首页时,会调用上面的代码,导致paddingTop是负数,图片上移,所以看起来上面有部分不见了。
修改为rootView.setPadding(0, 0, 0, 0);后发现可以用了
出现的问题:toolbar被覆盖了statusbar的位置,米3, Sys:6.1
xml:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dl_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#ccffee" />
<FrameLayout
android:id="@+id/fl_main_content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_main_menu_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start">
<FrameLayout
android:id="@+id/fl_main_menu"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
java:
@OverRide
public void setStatusBar() {
StatusBarUtils.setTranslucentForDrawerLayout(this, dl_main, 0);
}
系统5.0.2
CoordinatorLayout 为根布局的时候,貌似有问题,没有效果
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
报错地方:
private static void setRootView(Activity activity) {
ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
rootView.setFitsSystemWindows(true);
rootView.setClipToPadding(true);
}
这里拿不到根布局了
使用StatusBarUtil.setColorNoTranslucentForDrawerLayout()和StatusBarUtil.setColorForDrawerLayout()都没有效果,状态栏一直是默认的颜色,一直是colorPrimary设置的颜色
StatusBarUtil在CoordinatorLayout中无效,状态栏变白色
在华为emui3系统android5上运行时状态栏无反应
现在有四个Fragment来回之间的切换,首页的顶部是图片需要扩展到状态栏,就是沉浸式状态栏,但是其他的都是colorPrimary的颜色状态栏,,应该如何实现呢
StatusBarUtil.setTransparent(this);
StatusBarUtil.setTranslucent(this, StatusBarUtil.DEFAULT_STATUS_BAR_ALPHA);
状态栏都是白茫茫的一条,style文件设置了,找不到原因
StatusBarUtil.setColor(this, Color.BLUE);
<style name="Theme.AppCompat.Translucent" parent="AppTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation</item>
</style>
`_
_`
我现在遇到一个问题, 我在activity使用底部导航栏,然后再首页的fragment中 最上面的图片要做沉浸, 我试了你的方法, 没有实现。 求大神指教
本人手里有部Samsung A8000, 在这台手机上是你作者你写的setColor方法不能实现沉浸式效果,这个方法不能适用于手机5.0+的手机吗
界面布局:
<com.zhy.autolayout.AutoLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.zhy.autolayout.AutoRelativeLayout
android:layout_width="match_parent"
android:layout_height="180dp"
android:id="@+id/ll_img">
<ImageView
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"/>
<com.zhy.autolayout.AutoRelativeLayout
android:id="@+id/rl_off"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp">
<com.zhy.autolayout.AutoLinearLayout
android:id="@+id/manager_back"
android:layout_width="90px"
android:layout_height="70px"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginStart="6dp"
android:layout_marginTop="9dp">
<ImageView
android:layout_width="44px"
android:layout_height="41px"
android:src="@drawable/white_back"/>
</com.zhy.autolayout.AutoLinearLayout>
<TextView
android:layout_width="200dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="end"
android:textColor="@color/white"
android:id="@+id/text_event_name"
android:textSize="36px"
android:layout_alignTop="@+id/manager_back"
android:layout_centerHorizontal="true"
android:gravity="center"/>
</com.zhy.autolayout.AutoRelativeLayout>
<com.zhy.autolayout.AutoLinearLayout
android:id="@+id/ll_manager1"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="#33ffffff">
<com.zhy.autolayout.AutoLinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/manager_participants"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="42px"
android:textColor="@color/ff5c"
android:gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/participants"
android:textColor="@color/white"
android:textSize="24px"/>
</com.zhy.autolayout.AutoLinearLayout>
<com.zhy.autolayout.AutoLinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/manager_income"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="42px"
android:gravity="center"
android:textColor="@color/ff5c"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/income"
android:textColor="@color/white"
android:textSize="24px"/>
</com.zhy.autolayout.AutoLinearLayout>
<com.zhy.autolayout.AutoLinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/manager_checkin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="42px"
android:gravity="center"
android:textColor="@color/ff5c"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/checkin"
android:textColor="@color/white"
android:textSize="24px"/>
</com.zhy.autolayout.AutoLinearLayout>
</com.zhy.autolayout.AutoLinearLayout>
</com.zhy.autolayout.AutoRelativeLayout>
<com.zhy.autolayout.AutoFrameLayout
android:id="@+id/manager_framelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:visibility="gone">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/manager_progress"
android:layout_gravity="center"
android:visibility="gone"/>
</com.zhy.autolayout.AutoFrameLayout>
<com.zhy.autolayout.AutoRelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10px">
<ImageView
android:layout_width="42px"
android:layout_height="42px"
android:src="@drawable/ticket"
android:id="@+id/img_title_ticket"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginTop="15px"
android:layout_marginStart="15px" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="32px"
android:text="门票"
android:textColor="@color/black"
android:id="@+id/title_ticket"
android:layout_alignBottom="@+id/img_title_ticket"
android:layout_toEndOf="@+id/img_title_ticket"
android:layout_marginStart="10dp"
android:gravity="center"
android:layout_alignTop="@+id/img_title_ticket" />
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="@drawable/bg_shadow"
android:layout_below="@+id/img_title_ticket"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp"/>
</com.zhy.autolayout.AutoRelativeLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/manager_swiperefresh"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="@+id/lv_ticket"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cacheColorHint="@android:color/transparent"
android:listSelector="@android:color/transparent"
android:divider="@android:color/transparent"
android:dividerHeight="0dp">
</ListView>
</android.support.v4.widget.SwipeRefreshLayout>
</com.zhy.autolayout.AutoLinearLayout>
fragment调用:
@OverRide
public View onCreateView(LayoutInflater inflater, @nullable ViewGroup container, @nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.ticket, container, false);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
StatusBarUtil.setTranslucentForImageView(getActivity(),0,(ImageView)view.findViewById(R.id.banner));
}
return view;
}
在代码中设置状态栏透明后
StatusBarUtil.setTranslucent(this);
or
StatusBarUtil.setTranslucent(this, 0);
此 activity 对应的布局文件中根布局的 padding 属性不生效
Error:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (23.2.0) and test app (23.1.0) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
魅族Note3机型
StatusBarUtil.setColor(MainActivity.this, Color.BLACK);
设置后颜色时灵时不灵,有时候黑色,有时候透明,
开始进入是可以,A进入B页面,B页面顶部用的Imageview
StatusBarUtil.setTranslucentForImageView(this, 0, mRlayoutNoteDetailTop);
B返回到A页面,然后A的状态栏变为透明色,
我在A页面的OnResume也设置了
StatusBarUtil.setColor(MainActivity.this, Color.BLACK);
还是不可以!!
当向上滑动时,本该被状态栏遮住的toolbar却显示在了状态栏上面,
StatusBarUtil.setColorForDrawerLayout(this, drawer,
ContextCompat.getColor(this,R.color.colorPrimary), 0);
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:contentInsetStart="0dp"
app:layout_scrollFlags="scroll|enterAlways"
>
I cannot compile my app because
Manifest merger failed : Attribute application@allowBackup value=(false) from AndroidManifest.xml:14:9
is also present at com.jaeger.statusbaruitl:library:1.0.0:12:9 value=(true)
Suggestion: add 'tools:replace="android:allowBackup"' to <application> element at AndroidManifest.xml:12:5 to override
Maybe the issue is in the AndroidManifest.xml of the library
activity的页面使用Rele布局,然后在底部放置EditText,点击输入框,软键盘弹出,但是输入框没有跟随向上滑
because statusbar textcolor is white
but my app primarycolor is also white
我小米和各版本模拟器上将alpha设置为0为什么得到的却是一个浅灰色的状态栏背景
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
demo 中 ImageStatusBarActivity,现有的XML外面在包一层任意的根节点(ps:LinearLayout、RelativeLayout),在N5手机(6.0)上状态栏看起来就不是透明的,因为猴子图片没有顶上去,除非新加的根节点设置这张猴子图片。
那么我想问的是 是什么造成原有的图片没有match_parent呢 明明是这么设置的。。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent"
android:orientation="vertical">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_monkey">
<Button
android:id="@+id/btn_change_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_gravity="bottom|center_horizontal"
android:layout_margin="16dp"
android:text="Change Background" />
<SeekBar
android:id="@+id/sb_change_alpha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/btn_change_background"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp" />
<TextView
android:id="@+id/tv_status_alpha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/sb_change_alpha"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:textColor="@color/colorAccent"
android:textSize="36sp" />
</RelativeLayout>
</LinearLayout>
如果activity加了进入、退出动画,或者添加了右滑删除手势,体验不是很好,因为状态栏是独立而存在的。可否优化?
Obviously a product currently still has a lot of users whose android version is below 4.4…
StatusBarUtil.setColor(this, R.color.red)好像对4.4的miui无效,状态栏还是黑的
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.