我已实现此功能,使后退按钮出现并在我想要的某些时间消失。这有效,但按下它不会做任何事情。当我按下它时,我也无法找到被调用的函数,有人知道吗?
这是我的onCreate:
public class Homescreen extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
ActionBarDrawerToggle toggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_homescreen);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_open){
@Override
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
super.onDrawerSlide(drawerView, 0);
}
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
super.onDrawerSlide(drawerView, 0); // this disables the animation
}
};
drawer.setDrawerListener(toggle);
toggle.syncState();
drawer.setScrimColor(Color.TRANSPARENT);
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
if (savedInstanceState != null) {
return;
}
getSupportFragmentManager().beginTransaction()
.add(R.id.FragmentSpace, new GeneralFragment())
.commit();
}
public void BackNav(boolean y) {
if(y) {toggle.setDrawerIndicatorEnabled(false); getSupportActionBar().setDisplayHomeAsUpEnabled(true);} else {getSupportActionBar().setDisplayHomeAsUpEnabled(false);toggle.setDrawerIndicatorEnabled(true);}
}}
这也是我的工具栏:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay">
<TextView
android:id="@+id/actionbar_title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="top|center_horizontal"
android:layout_weight="1"
android:gravity="center"
android:text="my Title"
android:textColor="@color/barTextColor"
android:textSize="18sp"
app:layout_anchor="@+id/include"
app:layout_anchorGravity="top|center_horizontal" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>