![](/img/trans.png)
[英]How do I correctly anchor Snackbar in android, so it does not cover my bottom navigation view?
[英]I want to make navigation view on my tabs whereby u click the 3 bar it will so navigation view. How do i do that?
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/drawer">
<android.support.design.widget.NavigationView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:menu="@menu/nav_menu"
android:layout_gravity="start"
android:id="@+id/navigation_view"
></android.support.design.widget.NavigationView>
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#d3d3d3"
app:tabSelectedTextColor="#000000"
app:tabTextColor="#000000">
<android.support.design.widget.TabItem
android:id="@+id/tabItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="All Terminal" />
<android.support.design.widget.TabItem
android:id="@+id/tabItem1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Terminal 1" />
<android.support.design.widget.TabItem
android:id="@+id/tabItem2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Terminal 2" />
<android.support.design.widget.TabItem
android:id="@+id/tabItem3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Terminal 3" />
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
这是我现在在主页上显示的编码,而不是选项卡1 2或3。我要在您单击侧面导航选项卡将显示的3条时使导航显示。 我该如何更改XML文件呢? 现在,它显示了与我想要的东西不同的东西。
为此,您需要在java文件中实现逻辑:
在您的活动或Java文件中添加以下代码
final DrawerLayout drawerLayout=findViewById(R.id.drawerLayout);
TabLayout tabLayout = findViewById(R.id.tabs);
final int[] counterTabLast = {0};
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
if(tab.getPosition()==2){ //Position 2 means third tab
counterTabLast[0] = counterTabLast[0] +1;
if(counterTabLast[0] ==3){//
drawerLayout.openDrawer(Gravity.START); //Open Drawer
counterTabLast[0]=0;// Reset counter tab
}
}
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.