安卓隐藏状态栏
来源:互联网 发布:淘宝财务报表 编辑:程序博客网 时间:2024/05/18 00:57
以前为了美化界面,需要隐藏状态栏,但是每次隐藏后发现布局上串了,特别难看。最后我自己写一个方法来解决。
package com.neusoft.phone.xinhua;import android.content.Context;import android.os.Build;import android.text.Layout;import android.view.View;import android.view.WindowManager;import android.widget.LinearLayout;/** * Created by Administrator on 2016/11/26. */public class Util { public static void setToolbar(Context context,View layout,View view) { int titleH = (int) context.getResources().getDimension(R.dimen.title_bar_height); int toolbarH = getStatusBarHeight(context); LinearLayout.LayoutParams viewParams = (LinearLayout.LayoutParams) view.getLayoutParams(); // 取控件mGrid当前的布局参数 viewParams.height = toolbarH;// 当控件的高强制设成状态栏高度 view.setLayoutParams(viewParams); // 使设置好的布局参数应用到控件view LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) layout.getLayoutParams(); // 取控件mGrid当前的布局参数 layoutParams.height = toolbarH+titleH;// 当控件的高强制设成状态栏高度 layout.setLayoutParams(layoutParams); // 使设置好的布局参数应用到控件view } /* * get toolbar height */ public static int getStatusBarHeight(Context context) { int result = 0; int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { result = context.getResources().getDimensionPixelSize(resourceId); } return result; }}
下面为Activity(注意我传的参数)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); } setContentView(R.layout.report_activity_my_report); Util.setToolbar(getApplicationContext(),findViewById(R.id.toolbarllayout),findViewById(R.id.toolbarview));
xml部分:<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/toolbarllayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/report_title_bg" android:orientation="vertical"> <TextView android:id="@+id/toolbarview" android:layout_width="match_parent" android:layout_height="wrap_content" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="@dimen/title_bar_height" android:gravity="center_vertical" > <TextView android:id="@+id/topbar_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="@string/report_my_report" android:textColor="@color/white" android:textSize="@dimen/title_text_size" /> <ImageButton android:id="@+id/back" style="@style/friend_circle_title_icon_style" android:layout_alignParentLeft="true" android:layout_marginLeft="@dimen/title_icon_margin_left_and_right" android:contentDescription="@null" android:src="@drawable/btn_blue_left_selector" /> <ImageButton android:id="@+id/add" android:layout_width="@dimen/topic_my_topic_add_img_size" android:layout_height="@dimen/topic_my_topic_add_img_size" android:layout_centerVertical="true" android:layout_alignParentRight="true" android:layout_marginRight="@dimen/topic_new_topic_submit_text_margin_left_and_right" android:background="@drawable/topic_report_add" /> </RelativeLayout> </LinearLayout></LinearLayout>
搞定!
0 0
- 安卓隐藏状态栏
- 安卓隐藏标题栏和状态栏
- 安卓开发——隐藏状态栏和操作栏
- 安卓状态栏+kitkat
- # 安卓透明状态栏
- 安卓自学,手机上的横竖屏切换,状态栏隐藏
- 安卓自定义状态栏颜色
- 安卓沉浸式状态栏
- 安卓自定义状态栏颜色
- 安卓沉浸式状态栏
- 安卓获得状态栏高度
- 安卓沉浸式状态栏
- 安卓状态栏颜色改变
- 安卓沉浸式状态栏
- 自定义状态栏颜色 安卓
- 安卓去掉顶部状态栏
- 安卓沉浸式状态栏
- 安卓沉浸式状态栏
- 十进制小数转化为二进制数
- macbook air 单独安装纯净win7OS
- 字符串对比
- 用dd实现linux硬盘备份
- Leetcode14. Longest Common Prefix
- 安卓隐藏状态栏
- POJ_3255 Roadblocks(最短路)
- JDK和JRE
- 不改变数组的值对数组进行排序
- HTML<base>标签
- 针对MySQL创建用户后无法登录的原因
- 云客Drupal8源码分析之控制器执行及其解析器controller_resolver
- leetcode-FuzzBuzz
- 批量修改文件编码