androidの4.4版本沉浸式透明状态栏与导航栏案例

androidの4.4版本沉浸式透明状态栏与导航栏案例

1.  Android 系统自4.2 开始 UI 上就没多大改变,4.4 也只是增加了透明状态栏与导航栏的功能,如图
  
 看上去的确很好看样子,,接下来看看操作步骤:
protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_match_actionbar);

		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
			setTranslucentStatus(true);
		}

		SystemBarTintManager tintManager = new SystemBarTintManager(this);
		tintManager.setStatusBarTintEnabled(true);
		tintManager.setStatusBarTintResource(R.color.statusbar_bg2);

	}
我们看到在oncreate 方法中,布局xml 不做更改。

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setTranslucentStatus(true);
}
这里是更改的状态栏里透明的;调用方法setTranslucentStatus(true);
@TargetApi(19) 
private void setTranslucentStatus(boolean on) {
		Window win = getWindow();
		WindowManager.LayoutParams winParams = win.getAttributes();
		final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
		if (on) {
			winParams.flags |= bits;
		} else {
			winParams.flags &= ~bits;
		}
		win.setAttributes(winParams);
}

然后看到下面有
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
tintManager.setStatusBarTintResource(R.color.statusbar_bg2);
这里有个设置颜色值,即为当前状态栏的颜色。

那么更改了状态栏颜色值后, Actionbar颜色值也要变化啊,,,不急,继续下面更改actionbar颜色
在主配置文件中,
android:theme="@style/ActionBarTheme"
然后定义该样式即可
    <style name="ActionBarTheme" parent="android:Theme.Holo.Light.DarkActionBar">
        <!-- API 14 theme customizations can go here. -->
        <item name="android:actionBarStyle">@style/ActionBarStyle</item>
    </style>
    
    <style name="ActionBarStyle" parent="android:Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@color/actionbar_bg</item>
    </style>
这里background就是actionbar 颜色值啦。。。


以上就实现了完整更改。。。源码群里奉上。。
 欢迎进入 android 学习群:191974931

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值