美文网首页
底部导航栏中间加按钮的简单解决

底部导航栏中间加按钮的简单解决

作者: 庞哈哈哈12138 | 来源:发表于2017-06-17 13:08 被阅读0次

先看效果图:



其实实现方法非常多,我就用了一种最偷懒的方法
导航栏就用普通布局实现的,不用radiobutton,不用bootmnavigationbutton,就正常的布局:
上面加了framelayout 是为了给fragment占位

<FrameLayout
    android:layout_above="@+id/bootomlayout"
    android:id="@+id/oa_fragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

<LinearLayout
    android:id="@+id/bootomlayout"
    android:layout_alignParentBottom="true"
    android:layout_width="match_parent"
    android:layout_height="55dp">

    <LinearLayout
        android:id="@+id/lingjian_but"
        android:clickable="true"
        android:gravity="center"
        android:background="@color/changebackground"
        android:orientation="vertical"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="match_parent">

        <View
            android:layout_marginBottom="5dp"
            android:background="@color/xian"
            android:layout_width="match_parent"
            android:layout_height="1dp"/>


        <ImageView
            android:id="@+id/Lj_icon"
            android:src="@drawable/tab_renwuguanli_pre"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"/>

        <TextView
            android:id="@+id/Lj_text"
            android:paddingTop="5dp"
            android:paddingBottom="5dp"
            android:text="令箭"
            android:textSize="14sp"
            android:textColor="@color/white"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/oa_but"
        android:gravity="center"
        android:clickable="true"
        android:background="@color/changebackground"
        android:orientation="vertical"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="match_parent">

        <View
            android:layout_marginBottom="5dp"
            android:background="@color/xian"
            android:layout_width="match_parent"
            android:layout_height="1dp"/>

        <ImageView

            android:id="@+id/oa_icon"
            android:src="@drawable/tab_oaofficework_nor"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"/>

        <TextView
            android:id="@+id/oa_text"
            android:paddingTop="5dp"
            android:paddingBottom="5dp"
            android:textSize="14sp"
            android:textColor="@color/tab1"
            android:text="OA办公"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>


</LinearLayout>

<LinearLayout
    android:id="@+id/add_renwu"
    android:orientation="horizontal"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="10dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <ImageView
        android:layout_gravity="center_vertical"
        android:src="@drawable/tab_btn_add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

然后在activity中:
其实就是两个按钮切换时候改变文字颜色更换图标,然后切换fragment屏蔽掉中间按钮点击事件,在fragment写个透明的imagebutton,然后设置点击事件就行了,这样看起来即使切换页面点击事件不一样了,按钮没变



可以看到点击按钮弹得吐司

FragmentManager fr = getSupportFragmentManager();
        FragmentTransaction ft = fr.beginTransaction();
        centerfragment = new CenterFragment();
        ft.add(R.id.oa_fragment,centerfragment).hide(centerfragment).commit();

        Lj_but.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isOA = 1;
                addrenwu_bt.setClickable(true);
                FragmentManager fr = getSupportFragmentManager();
                FragmentTransaction ft = fr.beginTransaction();
                ft.hide(centerfragment).commit();

                Lj_text.setTextColor(getResources().getColor(R.color.white));
                Lj_icon.setImageResource(R.drawable.tab_renwuguanli_pre);
//                Lj_but.setBackgroundResource(R.color.tab1);

//                OA_but.setBackgroundResource(R.color.tab2);
                OA_icon.setImageResource(R.drawable.tab_oaofficework_nor);
                OA_text.setTextColor(getResources().getColor(R.color.tab1));
            }
        });

        OA_but.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isOA = 2;
                addrenwu_bt.setClickable(false);
                FragmentManager fr2 = getSupportFragmentManager();
                FragmentTransaction ft2 = fr2.beginTransaction();
                ft2.show(centerfragment).commit();


//                OA_but.setBackgroundResource(R.color.tab1);
                OA_icon.setImageResource(R.drawable.tab_oaofficework_pre);
                OA_text.setTextColor(getResources().getColor(R.color.white));

                Lj_text.setTextColor(getResources().getColor(R.color.tab1));
                Lj_icon.setImageResource(R.drawable.tab_renwuguanli_nor);
//                Lj_but.setBackgroundResource(R.color.tab2);
            }
        });

demo地址:https://github.com/PangHaHa12138/BootmButtonDemo

相关文章

网友评论

      本文标题:底部导航栏中间加按钮的简单解决

      本文链接:https://www.haomeiwen.com/subject/wxgmqxtx.html