0

enter image description here

The drew the red line to show where the orange line should keep going.

After searching similar questions, I could not find a way to solve my problem. I have a toggle button that shows in my Activity but when I press it, it doesn't open the navigation drawer (if I slide my finger it opens).

*The toggle button shows in the activity (the toolbar is transparent)

OnCreate and 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 code:

<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>
Lucas Heise
  • 139
  • 3
  • 12
  • 1
    You have two options. The first is to override the `Activity`'s `onOptionsItemSelected()` method, as shown in the answer on the first linked duplicate. The second is to simply add your `toolbar` as a third argument in the `ActionBarDrawerToggle` constructor call, as shown in the answers on the second linked duplicate. – Mike M. Apr 05 '19 at 15:06
  • I tried both of the answers but none of them seems to work for me – Lucas Heise Apr 05 '19 at 15:41
  • 1
    Hmm, well, then it would seem that we don't have enough information, here. Adding that `toolbar` argument should've definitely done it, provided the given layout is correct. Please add the complete `onCreate()` method from `MainActivity` (assuming that code is in `onCreate()` there). – Mike M. Apr 05 '19 at 16:37
  • @MikeM.Just edited my question. Adding that fourth argument in the Toolbar doesn't work as weel and the hamburguer icon changes to the back arrow icon – Lucas Heise Apr 05 '19 at 18:07
  • 1
    Ah, cool. Thank you. Now, since you have a `FloatingActionButton` in your code, there, and the `` in the XML isn't closed, I would assume that there's more to the layout that isn't shown. I would then guess that something is covering the `Toolbar`, and preventing touch events from reaching it. It's a rather common issue. What else do you have in the layout? Do you perhaps have something listed after the ``, that might be `match_parent`, or otherwise overlapping the `Toolbar` somehow? – Mike M. Apr 05 '19 at 18:12
  • I actually have more in the layout but the problem is that is generated programatically (after the toolbar tag, I have a LinearLayout (wrapper_layout) that covers the whole screen), and inside this LinearLayout is the place that I generate all the dynamic xml). I'll put that on my question as well – Lucas Heise Apr 05 '19 at 18:15
  • 1
    Yeah, that's part of our problem. The `` is covering the ``. Remove the inner ``, and change the outer `` to a vertical ``. Follow me? Also, the toggle being an arrow is because the `toggle.syncState()` call needs to be after the `getSupportActionBar()` calls. – Mike M. Apr 05 '19 at 18:27
  • I tried that and the opening of the drawer worked but the problem now is that the wrapper_layout needs to get the whole screen (the toolbar is invisible and the content of the wrapper_layout needs to cover the whole screen). Is it possible? I can attach a picture if you don't get what I mean. – Lucas Heise Apr 05 '19 at 18:34
  • 1
    Ooohh, I see what you were going for. Hold on. I was redoing your layout anyway, 'cause I changed my comment, and figured it'd be confusing. Gimme a second, and I'll post the corrections. – Mike M. Apr 05 '19 at 18:40
  • Just added a picture to make it more clear – Lucas Heise Apr 05 '19 at 18:44
  • 1
    Here ya go: https://drive.google.com/file/d/1firYRNcdlEe81gVPS8DPOzJBl5AYS_7Q/view?usp=drivesdk. Give that a shot. – Mike M. Apr 05 '19 at 18:45
  • 1
    IT WORKED, thank you veery much. I was actually really surprise to see that you went through all the trouble to recreate my layout hahaha. Once again thank you very much, you're a life saver. – Lucas Heise Apr 05 '19 at 18:53
  • No problem. I always feel a bit of responsibility when I close a question as a duplicate. From the original code and layout XML, I figured this was just a pretty cut-and-dry instance of my initial suggested issue. Guess there were some other things happening, too. :-) Anyhoo, glad you got it working. Cheers! – Mike M. Apr 05 '19 at 18:57

0 Answers0