沉浸式状态栏
来源:互联网 发布:什么是程序员 编辑:程序博客网 时间:2024/06/16 10:54
沉浸式效果-最低支持到v19
方法1:values-v19下的styles.xml 设置windowTranslucentStatus为true
方法2:java中设置
注:以上方式支持一般的页面,但是像侧滑栏菜单这种事支持不了的!
关于侧滑栏菜单的沉侵式效果
依然要创建一个BaseActivity:
@TargetApi(19) @Override protected void onCreate(Bundle savedInstanceState) { if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) { // // 全屏不隐藏状态栏 getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); // 设置状态栏透明 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); } super.onCreate(savedInstanceState); }
子Activity继承
@TargetApi(19) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv_status = (TextView) findViewById(R.id.tv_status); if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) { tv_status.setHeight(getStatusHeight(this)); tv_status.setVisibility(View.VISIBLE); } else { tv_status.setHeight(0); tv_status.setVisibility(View.GONE); } } //getStatusHeight方法为计算状态栏高度的方法: public int getStatusHeight(Activity activity) { int statusHeight = 0; Rect localRect = new Rect(); activity.getWindow().getDecorView() .getWindowVisibleDisplayFrame(localRect); statusHeight = localRect.top; if (0 == statusHeight) { Class<?> localClass; try { localClass = Class.forName("com.android.internal.R$dimen"); Object localObject = localClass.newInstance(); int i5 = Integer.parseInt(localClass .getField("status_bar_height").get(localObject) .toString()); statusHeight = activity.getResources() .getDimensionPixelSize(i5); } catch (Exception e) { e.printStackTrace(); } } return statusHeight; }
布局Xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/tv_status" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#00ccee" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="50dp" android:background="#00ccee" > <TextView android:id="@+id/tv_menu" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="10dp" android:text="菜单" android:textColor="#FFFFFF" android:textSize="14sp" /> <TextView android:id="@+id/tv_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="消息" android:textColor="#FFFFFF" android:textSize="18sp" /> </RelativeLayout></LinearLayout>
注:tv_status控件就是用来设置为状态栏高度的
0 0
- 状态栏、沉浸式状态栏
- 沉浸式状态栏/透明状态栏
- 透明状态栏(沉浸式状态栏)
- Android 沉浸式状态栏
- 沉浸式状态栏
- android 沉浸式 状态栏
- android 沉浸式状态栏
- android沉浸式状态栏
- 沉浸式状态栏
- Android沉浸式状态栏
- Android 沉浸式状态栏
- 沉浸式状态栏
- 沉浸式状态栏
- android 沉浸式状态栏
- Android沉浸式状态栏
- 设置沉浸式状态栏
- Android沉浸式状态栏
- 沉浸式状态栏
- POJ 1947 Rebuilding Roads ( 树形DP )
- BZOJ3441 乌鸦喝水
- Linux下安装Jetty服务器部署Jenkins
- 【第一行代码-Android】学习(一)及在studio的迁移(4)intent学习
- bootstrap中tab的跳转问题
- 沉浸式状态栏
- 设计模式学习笔记--工厂方法模式(Factory Method Pattern)【创建型模式】
- Jenkins简介
- [知其然不知其所以然-36] wakeup by pci devices
- charCodeAt 和 String.fromCharCode 用法
- ThinkPHP内容管理系统开发日记(一)--规划数据库。
- Jenkins 简单使用
- SVN认证失败的错误分析
- HDU1076——An Easy Task