Android底部菜单栏、Android沉浸式状态栏(顶部状态栏修改颜色)、自定义标题栏

0、简介:

没有使用TabHost切换,而是变成FragmentActivity替换Fragment;沉浸式引用的git上面的jar包。

先看图片

1、底部导航栏

核心代码

<span style="white-space:pre">	</span>/**
	 * 
	 * @param v
	 *            设置图标字体状态、改变颜色
	 */
	private void setBottom(View v) {
		//如果和上次点击的View不同并且不为空、设置上次的选中状态为false;
		if (currentView != null && !currentView.equals(v)) {
			currentView.setSelected(false);
		}
		currentView = v;
		currentView.setSelected(true);
	}

2、Android沉浸式状态栏(顶部状态栏修改颜色)

核心代码:

在修改之前要在xml根部添加俩个参数

    android:clipToPadding="true"
    android:fitsSystemWindows="true"
解释:

android:clipToPadding 定义布局间是否有间距;

android:fitsSystemWindows="true" 你的布局是否要考虑系统状态栏;如果不设置这两个参数,可能你的布局会挡住系统状态栏。

<span style="white-space:pre">		</span>// 设置当前Activity
		SettingHelper.getInstance().setCurrentActivity(MainActivity.this);
		// 设置状态栏为自定义颜色
		UIHelper.getInstance().setSystemBar();

<span style="white-space:pre">	</span>/**
	 * 设置系统状态栏
	 */
	public void setSystemBar() {
		// 修改沉浸式状态栏 要大于Android系统4.4 版本API19
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
			setTranslucentStatus(true);
		}
		Activity activity = SettingHelper.getInstance().getCurrentActivity();
		// 获取系统状态栏管理者
		SystemBarTintManager manager = new SystemBarTintManager(activity);
		// 是否修改
		manager.setStatusBarTintEnabled(true);
		// 修改的颜色
		manager.setStatusBarTintResource(R.color.app_overall);
	}

	@TargetApi(Build.VERSION_CODES.KITKAT)
	private void setTranslucentStatus(boolean is) {
		// 获取当前Activity
		Activity activity = SettingHelper.getInstance().getCurrentActivity();
		Window window = activity.getWindow();
		WindowManager.LayoutParams params = window.getAttributes();
		final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
		if (is) {
			// 或之后赋予值
			params.flags |= bits;
		} else {
			// 与之后赋予值
			params.flags &= ~bits;
		}
		// 设置状态参数
		window.setAttributes(params);
	}

3、标题栏

代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_head"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:background="@color/app_overall" >

    <RelativeLayout
        android:id="@+id/layout_head_left_r"
        android:layout_width="80dp"
        android:layout_height="match_parent"
        android:layout_marginLeft="10dp" >

        <ImageView
            android:id="@+id/layout_head_left_iv"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_centerVertical="true"
            android:contentDescription="@string/app_name"
            android:src="@drawable/back_wihte"
            android:visibility="gone" />

        <TextView
            android:id="@+id/layout_head_left_tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:text="@string/app_back"
            android:textColor="@color/app_white"
            android:textSize="15sp"
            android:visibility="gone" />
    </RelativeLayout>

    <LinearLayout
        android:id="@+id/layout_head_centre_l"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/layout_head_centre_iv"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center_vertical"
            android:contentDescription="@string/app_name"
            android:src="@drawable/menu_about"
            android:visibility="gone" />

        <TextView
            android:id="@+id/layout_head_centre_tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginRight="3dp"
            android:text="@string/app_back"
            android:textColor="@color/app_white"
            android:textSize="15sp"
            android:visibility="gone" />
    </LinearLayout>

    <RelativeLayout
        android:id="@+id/layout_head_right_r"
        android:layout_width="80dp"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:layout_marginRight="10dp" >

        <ImageView
            android:id="@+id/layout_head_right_iv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:contentDescription="@string/app_name"
            android:src="@drawable/menu_about"
            android:visibility="gone" />

        <TextView
            android:id="@+id/layout_head_right_tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:text="@string/app_back"
            android:textColor="@color/app_white"
            android:textSize="15sp"
            android:visibility="gone" />
    </RelativeLayout>

</RelativeLayout>

4、下载地址

下载项目链接(包括引入库)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值