Android设置沉浸式状态栏和Material主题
来源:互联网 发布:淘宝店铺宝贝详情教程 编辑:程序博客网 时间:2024/05/22 13:01
出处:http://blog.csdn.net/android_zhengyongbo/article/details/69396242
1.设置沉浸式状态栏的方法
/**
* true 进入全屏模式,状态栏不显示
* false 显示状态栏
*/
public static void setSystemUiVisibility(Activity activity, boolean enterFullscreen) { if (activity == null) { return; } View decor = activity.getWindow().getDecorView(); if (enterFullscreen) { activity.getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } else { activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); } /* place the window within the entire screen, ignoring * decorations around the border (such as the status bar).*/ activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { return; } Window window = activity.getWindow(); // Translucent status bar window.setFlags( WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); // Translucent navigation bar window.setFlags( WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); int systemUiVisibility = decor.getSystemUiVisibility(); int flags = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; if (enterFullscreen) { systemUiVisibility |= flags; } else { systemUiVisibility &= ~flags; } decor.setSystemUiVisibility(systemUiVisibility); }/****是否进入全屏模式**/ public static boolean isFullScreenActivity(Activity activity) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { return (activity.getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) > 0; } View decor = activity.getWindow().getDecorView(); int systemUiVisibility = decor.getSystemUiVisibility(); int flags = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; return (systemUiVisibility & flags) == flags; }
2.使用Material主题(比较倾向于这种方法)
在BaseActivity中添加下面代码
requestWindowFeature(Window.FEATURE_NO_TITLE);//无标题 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//竖直方向 this.TAG = getClass().getSimpleName(); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);//软键盘自适应
修改状态栏颜色只有在5.0及以上的版本才会生效,首先查看styles.xml中是否存在AppTheme:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here. --> </style> 然后新建values-v19,values-v21文件,创建styles.xml文件,添加主题: <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!--状态栏颜色--> <item name="android:colorPrimaryDark">@color/colorAccent</item> <!--ActionBar颜色--> <item name="android:colorPrimary">#ff0</item> <!--界面背景颜色--> <item name="android:windowBackground">@color/colorAccent</item> <!--导航栏颜色--> <item name="android:navigationBarColor">#f00</item> </style>
最后将Manifest里面的主题更换为AppTheme就行了。这是我第一次写自己的博客,本博客主要是为了自我学习和提高,若能帮助到您将欣喜万分!!!
0 0
- Android设置沉浸式状态栏和Material主题
- android 配置Material Design主题(沉浸式状态栏的实现)
- android设置沉浸式状态栏
- 【Android】沉浸式状态栏设置
- Android状态栏颜色设置(沉浸式状态栏)
- Android 设置状态栏颜色&&沉浸式状态栏
- Android沉浸式和状态栏透明设置笔记!
- android沉浸式 & 状态栏颜色设置
- Android沉浸式(设置状态栏颜色)
- android沉浸状态栏和顶部状态栏背景色的设置
- 关于Android主题splash全屏和主页面的沉浸式状态栏
- 设置沉浸式状态栏
- 设置沉浸式状态栏
- 设置沉浸式状态栏
- 设置沉浸式状态栏
- Android关于全屏设置和隐藏状态栏、沉浸式状态栏的总结
- android设置状态栏颜色(沉浸式状态栏)
- Android 沉浸式状态栏 一设置状态栏颜色
- 排序算法,java
- 建造者模式
- Hibernate框架的了解
- Ubuntu下boot分区剩余空间不足解决
- new的用法
- Android设置沉浸式状态栏和Material主题
- asp.net js方法互调 asp.net 前台如何调用后台方法
- 2017年PHP程序员未来路在何方
- C++ 程序调试与异常处理
- 安卓手机常用ADB命令
- C语言内存机制详解
- java 防SQL注入正则
- 移动端开发调支付宝支付接口遇到的问题
- string substr()