底部導(dǎo)航欄中間加按鈕的簡單解決

先看效果圖:



其實實現(xiàn)方法非常多,我就用了一種最偷懶的方法
導(dǎo)航欄就用普通布局實現(xiàn)的,不用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,然后設(shè)置點擊事件就行了,這樣看起來即使切換頁面點擊事件不一樣了,按鈕沒變



可以看到點擊按鈕彈得吐司

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容