Android System Bar Tint 沉浸式菜单栏使用教程
来源:互联网 发布:吾知子之所以距我的之 编辑:程序博客网 时间:2024/06/06 01:35
https://github.com/jgilfelt/SystemBarTint
1.状态栏支持图片显示。
2.状态栏支持颜色变换。
安装:
下载JAR文件如何载入你的工程或者在build.gradle中添加到dependency中,如下所示:
dependencies {
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
}
如何使用:
在theme属性中设置android:windowTranslucentNavigation or android:windowTranslucentStatus 为true或者在代码中设置activity的flags为: FLAG_TRANSLUCENT_NAVIGATION or FLAG_TRANSLUCENT_STATUS。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setTranslucentStatus(true);
}
判断当前的sdk版本高于19,即Android4.4版本,条件成立才设置沉浸式菜单栏。
private Button mBlueButton;
private Button mGreenButton;
private Button mRedButton;
private SystemBarTintManager tintManager;
private DrawerLayout mDrawerLayout;
private TextView mTextViewContain;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_scroll_view_demo_activity);
mBlueButton = (Button) findViewById(R.id.mBlueButton);
mGreenButton = (Button) findViewById(R.id.mGreenButton);
mRedButton = (Button) findViewById(R.id.mRedButton);
mTextViewContain = (TextView) findViewById(R.id.mTextViewContain);
mBlueButton.setOnClickListener(this);
mGreenButton.setOnClickListener(this);
mRedButton.setOnClickListener(this);
// 使用条件判断
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setTranslucentStatus(true);
}
tintManager = new SystemBarTintManager(this);
// 设置状态栏可用
tintManager.setStatusBarTintEnabled(true);
// 设置导航栏不可用
tintManager.setNavigationBarTintEnabled(false);
// 在这获取状态栏的配置信息
SystemBarTintManager.SystemBarConfig config = tintManager.getConfig();
mTextViewContain.setText("" + config.getStatusBarHeight() + "+" + config.getActionBarHeight());
// Rect outRect = new Rect();
// getWindow().getDecorView().getWindowVisibleDisplayFrame(outRect);
mDrawerLayout = (DrawerLayout) findViewById(R.id.id_drawerlayout);
mDrawerLayout.setDrawerListener(this);
}
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);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.mBlueButton:
// tintManager.setStatusBarTintColor(Color.BLUE);
tintManager.setTintDrawable(getResources().getDrawable(R.drawable.view_1));
break;
case R.id.mGreenButton:
tintManager.setStatusBarTintColor(Color.GREEN);
break;
case R.id.mRedButton:
tintManager.setStatusBarTintColor(0x33ff0000);
break;
}
}
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
// tintManager.setStatusBarTintColor(0x3300ff00);
}
@Override
public void onDrawerOpened(View drawerView) {
}
@Override
public void onDrawerClosed(View drawerView) {
}
@Override
public void onDrawerStateChanged(int newState) {
}
}
styles.xml文件
设置windowIsTranslucent为true
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowIsTranslucent">true</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
注:
在activity布局文件中添加属性,让activity适应屏幕和状态栏显示
android:fitsSystemWindows="true"
0 0
- Android System Bar Tint 沉浸式菜单栏使用教程
- android Translucent Bar (沉浸式菜单栏)
- Android UI之沉浸式状态栏Translucent System Bar
- android中沉浸式菜单栏
- 转-android沉浸式状态栏:Translucent System Bar 的最佳实践
- (4.2.37.1)沉浸式状态栏Android开发:Translucent System Bar 的最佳实践
- Android开发 -- Translucent System Bar 的最佳实践(沉浸式状态栏)
- Android开发:Translucent System Bar 的最佳实践(沉浸式)
- android tint selector 使用
- Android中Tint使用
- Android Tint使用
- Android-Tint使用实践
- Android Translucent System Bar 开发详解-实现沉浸式通知栏(通知栏与导航栏颜色相同)
- Android Translucent System Bar使用小结
- 环信使用沉浸式菜单栏输入框问题
- 沉浸式状态栏,菜单栏一体化
- Android之Translucent Bar半透明栏和immersive bar沉浸式的区别
- Android中显示,隐藏Status Bar和Navigation Bar,沉浸式体验
- CC2540功率设置
- mySql的简单应用
- markdown文件初体验
- Files IO in C
- 把list对象转换成xml字符串
- Android System Bar Tint 沉浸式菜单栏使用教程
- android 的 两个不错的网站 (有很多功能 和 特效)
- 一个IT人的职业规划
- perl 写入到压缩文件
- ERstudio导入mysql脚本生成rtf文档
- Coding.net代码托管空间申请与使用
- C++类的六个重要函数
- 北斗七星问题
- 关于数论