画出红线以显示橙色线应继续前进的地方。
搜索类似的问题后,我找不到解决问题的方法。 我有一个切换按钮显示在我的活动中,但是当我按下它时,它不会打开导航抽屉(如果我滑动手指会打开它)。
*活动中显示切换按钮(工具栏为透明)
OnCreate和onOptionsItemSelect
ActionBarDrawerToggle toggle;
DrawerLayout drawer;
NavigationView navigationView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.my_toolbar);
setSupportActionBar(toolbar);
drawer = findViewById(R.id.drawer_layout);
toggle = new ActionBarDrawerToggle
(
this,
drawer,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close
)
{
};
drawer.addDrawerListener(toggle);
toggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setTitle("");
toggle.getDrawerArrowDrawable().setColor(getResources().getColor(R.color.colorPrimaryDark));
FloatingActionButton fab = findViewById(R.id.action_btn);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(), NewEventActivity.class);
startActivity(intent);
/*Intent intent = new Intent(getApplicationContext(), testes.class);
startActivity(intent);*/
}
});
navigationView = findViewById(R.id.navigation_view);
navigationView.setNavigationItemSelectedListener(this);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(toggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
XML代码:
<android.support.v4.widget.DrawerLayout
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"
tools:context=".MainActivity"
android:id="@+id/drawer_layout">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:title=""
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/wrapper_layout">
</LinearLayout>
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/action_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:backgroundTint="#FE7D4B"
app:srcCompat="@drawable/ic_add" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="@menu/drawer_menu"
android:layout_gravity="start"
android:id="@+id/navigation_view"
>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>