先看效果圖:
其實實現(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);
}
});