Android最全Android - 沉浸式状态栏(2),2024年最新android个人信息界面设计

最后

文章所有资料全部已经打包整理好,另外小编手头上整理了大量Android架构师全套学习资料,Android核心高级技术PDF文档+全套高级学习资料+视频+2021 BAT 大厂面试真题解析

资料展示:

image

image

image

image

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

@Override

public void onWindowFocusChanged(boolean hasFocus) {

super.onWindowFocusChanged(hasFocus);

if (hasFocus && Build.VERSION.SDK_INT >= 19) {

View decorView = getWindow().getDecorView();

decorView.setSystemUiVisibility(

View.SYSTEM_UI_FLAG_LAYOUT_STABLE

| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION

| View.SYSTEM_UI_FLAG_FULLSCREEN

| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

}

}

}

方式2.透明状态栏效果,需要在5.0及其以上系统才支持。

  • 布局文件
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout 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”

tools:context=“com.mythmayor.a1805statusbardemo.Status2Activity”>

<ImageView

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:scaleType=“centerCrop”

android:src=“@mipmap/mythmayor_bg03” />

  • Java代码

package com.mythmayor.a1805statusbardemo;

import android.graphics.Color;

import android.os.Build;

import android.os.Bundle;

import android.support.v7.app.ActionBar;

import android.support.v7.app.AppCompatActivity;

import android.view.View;

public class Status2Activity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_status2);

if (Build.VERSION.SDK_INT >= 21) {

View decorView = getWindow().getDecorView();

int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;

decorView.setSystemUiVisibility(option);

getWindow().setStatusBarColor(Color.TRANSPARENT);

}

ActionBar actionBar = getSupportActionBar();

actionBar.hide();

}

}

方式3.将状态栏和导航栏设置为透明

  • Step1 在布局文件根布局中加入下面代码

android:fitsSystemWindows=“true”

  • Step2 在Activity文件的setContent()方法之前加入下面代码

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

//透明状态栏

getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

//透明导航栏

getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

}

方式4.将状态栏和导航栏设置为透明

  • Step1 在布局文件根布局中加入下面代码

android:fitsSystemWindows=“true”

  • Step2 使用SystemBarTintManager和StatusBarUtil对状态栏进行设置
只需一行代码即可设置指定颜色的沉浸式状态栏

/** 设置沉浸式状态栏 */

StatusBarUtil.initSystemBar(this, R.color.white);

下面附上代码
SystemBarTintManager.java

import android.annotation.SuppressLint;

import android.annotation.TargetApi;

import android.app.Activity;

import android.content.Context;

import android.content.res.Configuration;

import android.content.res.Resources;

import android.content.res.TypedArray;

import android.graphics.drawable.Drawable;

import android.os.Build;

import android.util.DisplayMetrics;

import android.util.TypedValue;

import android.view.Gravity;

import android.view.View;

import android.view.ViewConfiguration;

import android.view.ViewGroup;

import android.view.Window;

import android.view.WindowManager;

import android.widget.FrameLayout.LayoutParams;

import java.lang.reflect.Method;

public class SystemBarTintManager {

static {

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

try {

Class c = Class.forName(“android.os.SystemProperties”);

Method m = c.getDeclaredMethod(“get”, String.class);

m.setAccessible(true);

sNavBarOverride = (String) m.invoke(null, “qemu.hw.mainkeys”);

} catch (Throwable e) {

sNavBarOverride = null;

}

}

}

/**

  • The default system bar tint color value.

*/

public static final int DEFAULT_TINT_COLOR = 0x99000000;

private static String sNavBarOverride;

private final SystemBarConfig mConfig;

private boolean mStatusBarAvailable;

private boolean mNavBarAvailable;

private boolean mStatusBarTintEnabled;

private boolean mNavBarTintEnabled;

private View mStatusBarTintView;

private View mNavBarTintView;

/**

  • Constructor. Call this in the host activity onCreate method after its

  • content view has been set. You should always create new instances when

  • the host activity is recreated.

  • @param activity The host activity.

*/

@TargetApi(19)

@SuppressWarnings(“ResourceType”)

public SystemBarTintManager(Activity activity) {

Window win = activity.getWindow();

ViewGroup decorViewGroup = (ViewGroup) win.getDecorView();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

// check theme attrs

int[] attrs = {android.R.attr.windowTranslucentStatus,

android.R.attr.windowTranslucentNavigation};

TypedArray a = activity.obtainStyledAttributes(attrs);

try {

mStatusBarAvailable = a.getBoolean(0, false);

mNavBarAvailable = a.getBoolean(1, false);

} finally {

a.recycle();

}

// check window flags

WindowManager.LayoutParams winParams = win.getAttributes();

int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;

if ((winParams.flags & bits) != 0) {

mStatusBarAvailable = true;

}

bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;

if ((winParams.flags & bits) != 0) {

mNavBarAvailable = true;

}

}

mConfig = new SystemBarConfig(activity, mStatusBarAvailable, mNavBarAvailable);

// device might not have virtual navigation keys

if (!mConfig.hasNavigtionBar()) {

mNavBarAvailable = false;

}

if (mStatusBarAvailable) {

setupStatusBarView(activity, decorViewGroup);

}

if (mNavBarAvailable) {

setupNavBarView(activity, decorViewGroup);

}

}

/**

  • Enable tinting of the system status bar.

  • If the platform is running Jelly Bean or earlier, or translucent system

  • UI modes have not been enabled in either the theme or via window flags,

  • then this method does nothing.

  • @param enabled True to enable tinting, false to disable it (default).

*/

public void setStatusBarTintEnabled(boolean enabled) {

mStatusBarTintEnabled = enabled;

if (mStatusBarAvailable) {

mStatusBarTintView.setVisibility(enabled ? View.VISIBLE : View.GONE);

}

}

/**

  • Enable tinting of the system navigation bar.

  • If the platform does not have soft navigation keys, is running Jelly Bean

  • or earlier, or translucent system UI modes have not been enabled in either

  • the theme or via window flags, then this method does nothing.

  • @param enabled True to enable tinting, false to disable it (default).

*/

public void setNavigationBarTintEnabled(boolean enabled) {

mNavBarTintEnabled = enabled;

if (mNavBarAvailable) {

mNavBarTintView.setVisibility(enabled ? View.VISIBLE : View.GONE);

}

}

/**

  • Apply the specified color tint to all system UI bars.

  • @param color The color of the background tint.

*/

public void setTintColor(int color) {

setStatusBarTintColor(color);

setNavigationBarTintColor(color);

}

/**

  • Apply the specified drawable or color resource to all system UI bars.

  • @param res The identifier of the resource.

*/

public void setTintResource(int res) {

setStatusBarTintResource(res);

setNavigationBarTintResource(res);

}

/**

  • Apply the specified drawable to all system UI bars.

  • @param drawable The drawable to use as the background, or null to remove it.

*/

public void setTintDrawable(Drawable drawable) {

setStatusBarTintDrawable(drawable);

setNavigationBarTintDrawable(drawable);

}

/**

  • Apply the specified alpha to all system UI bars.

  • @param alpha The alpha to use

*/

public void setTintAlpha(float alpha) {

setStatusBarAlpha(alpha);

setNavigationBarAlpha(alpha);

}

/**

  • Apply the specified color tint to the system status bar.

  • @param color The color of the background tint.

*/

public void setStatusBarTintColor(int color) {

if (mStatusBarAvailable) {

mStatusBarTintView.setBackgroundColor(color);

}

}

/**

  • Apply the specified drawable or color resource to the system status bar.

  • @param res The identifier of the resource.

*/

public void setStatusBarTintResource(int res) {

if (mStatusBarAvailable) {

mStatusBarTintView.setBackgroundResource(res);

}

}

/**

  • Apply the specified drawable to the system status bar.

  • @param drawable The drawable to use as the background, or null to remove it.

*/

@SuppressWarnings(“deprecation”)

public void setStatusBarTintDrawable(Drawable drawable) {

if (mStatusBarAvailable) {

mStatusBarTintView.setBackgroundDrawable(drawable);

}

}

/**

  • Apply the specified alpha to the system status bar.

  • @param alpha The alpha to use

*/

@TargetApi(11)

public void setStatusBarAlpha(float alpha) {

if (mStatusBarAvailable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

mStatusBarTintView.setAlpha(alpha);

}

}

/**

  • Apply the specified color tint to the system navigation bar.

  • @param color The color of the background tint.

*/

public void setNavigationBarTintColor(int color) {

if (mNavBarAvailable) {

mNavBarTintView.setBackgroundColor(color);

}

}

/**

  • Apply the specified drawable or color resource to the system navigation bar.

  • @param res The identifier of the resource.

*/

public void setNavigationBarTintResource(int res) {

if (mNavBarAvailable) {

mNavBarTintView.setBackgroundResource(res);

}

}

/**

  • Apply the specified drawable to the system navigation bar.

  • @param drawable The drawable to use as the background, or null to remove it.

*/

@SuppressWarnings(“deprecation”)

public void setNavigationBarTintDrawable(Drawable drawable) {

if (mNavBarAvailable) {

mNavBarTintView.setBackgroundDrawable(drawable);

}

}

/**

  • Apply the specified alpha to the system navigation bar.

  • @param alpha The alpha to use

*/

@TargetApi(11)

public void setNavigationBarAlpha(float alpha) {

if (mNavBarAvailable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

mNavBarTintView.setAlpha(alpha);

}

}

/**

  • Get the system bar configuration.

  • @return The system bar configuration for the current device configuration.

*/

public SystemBarConfig getConfig() {

return mConfig;

}

/**

  • Is tinting enabled for the system status bar?

  • @return True if enabled, False otherwise.

*/

public boolean isStatusBarTintEnabled() {

return mStatusBarTintEnabled;

}

/**

  • Is tinting enabled for the system navigation bar?

  • @return True if enabled, False otherwise.

*/

public boolean isNavBarTintEnabled() {

return mNavBarTintEnabled;

}

private void setupStatusBarView(Context context, ViewGroup decorViewGroup) {

mStatusBarTintView = new View(context);

LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, mConfig.getStatusBarHeight());

params.gravity = Gravity.TOP;

if (mNavBarAvailable && !mConfig.isNavigationAtBottom()) {

params.rightMargin = mConfig.getNavigationBarWidth();

}

mStatusBarTintView.setLayoutParams(params);

mStatusBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR);

mStatusBarTintView.setVisibility(View.GONE);

decorViewGroup.addView(mStatusBarTintView);

}

private void setupNavBarView(Context context, ViewGroup decorViewGroup) {

mNavBarTintView = new View(context);

LayoutParams params;

if (mConfig.isNavigationAtBottom()) {

params = new LayoutParams(LayoutParams.MATCH_PARENT, mConfig.getNavigationBarHeight());

params.gravity = Gravity.BOTTOM;

} else {

params = new LayoutParams(mConfig.getNavigationBarWidth(), LayoutParams.MATCH_PARENT);

params.gravity = Gravity.RIGHT;

}

mNavBarTintView.setLayoutParams(params);

mNavBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR);

mNavBarTintView.setVisibility(View.GONE);

decorViewGroup.addView(mNavBarTintView);

}

/**

  • Class which describes system bar sizing and other characteristics for the current

  • device configuration.

*/

public static class SystemBarConfig {

结语

看到这篇文章的人不知道有多少是和我一样的Android程序员。

35岁,这是我们这个行业普遍的失业高发阶段,这种情况下如果还不提升自己的技能,进阶发展,我想,很可能就是本行业的职业生涯的终点了。

我们要有危机意识,切莫等到一切都成定局时才开始追悔莫及。只要有规划的,有系统地学习,进阶提升自己并不难,给自己多充一点电,你才能走的更远。

千里之行始于足下。这是上小学时,那种一元钱一个的日记本上每一页下面都印刷有的一句话,当时只觉得这句话很短,后来渐渐长大才慢慢明白这句话的真正的含义。

有了学习的想法就赶快行动起来吧,不要被其他的事情牵绊住了前行的脚步。不要等到裁员时才开始担忧,不要等到面试前一晚才开始紧张,不要等到35岁甚至更晚才开始想起来要学习要进阶。

给大家一份系统的Android学习进阶资料,希望这份资料可以给大家提供帮助。

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

ility(View.GONE);

decorViewGroup.addView(mNavBarTintView);

}

/**

  • Class which describes system bar sizing and other characteristics for the current

  • device configuration.

*/

public static class SystemBarConfig {

结语

看到这篇文章的人不知道有多少是和我一样的Android程序员。

35岁,这是我们这个行业普遍的失业高发阶段,这种情况下如果还不提升自己的技能,进阶发展,我想,很可能就是本行业的职业生涯的终点了。

我们要有危机意识,切莫等到一切都成定局时才开始追悔莫及。只要有规划的,有系统地学习,进阶提升自己并不难,给自己多充一点电,你才能走的更远。

千里之行始于足下。这是上小学时,那种一元钱一个的日记本上每一页下面都印刷有的一句话,当时只觉得这句话很短,后来渐渐长大才慢慢明白这句话的真正的含义。

有了学习的想法就赶快行动起来吧,不要被其他的事情牵绊住了前行的脚步。不要等到裁员时才开始担忧,不要等到面试前一晚才开始紧张,不要等到35岁甚至更晚才开始想起来要学习要进阶。

给大家一份系统的Android学习进阶资料,希望这份资料可以给大家提供帮助。
[外链图片转存中…(img-P8lr4Fmz-1715175793970)]

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值