Button beneath navigation drawer not working when pressed

WoodburyRaider

Yet, when the button is placed in the hierarchy so that it can be seen on top of the navigation drawer, the button functions properly. However, the button should be hidden behind the navigation drawer when it is slid out, so this is not desirable.

Below is the code from MainActivity.java

public class MainActivity extends ActionBarActivity implements NavigationDrawerCallbacks {

public ProgressDialog progBar;

public final static boolean DEBUG = false;
public final static String TAG = "AppGetter";
private Toolbar mToolbar;
private NavigationDrawerFragment mNavigationDrawerFragment;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false); 

    mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.fragment_drawer);
    mNavigationDrawerFragment.setup(R.id.fragment_drawer, (DrawerLayout) findViewById(R.id.drawer), mToolbar);

    ImageButton cart_button = (ImageButton) findViewById(R.id.button2);
    cart_button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            start_request();

        }
    });



}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    return super.onCreateOptionsMenu(menu);
}

@Override
public void onNavigationDrawerItemSelected(int position) {
    Toast.makeText(this, "Menu item selected -> " + position, Toast.LENGTH_SHORT).show();
}

@Override
public void onBackPressed() {
    if (mNavigationDrawerFragment.isDrawerOpen())
        mNavigationDrawerFragment.closeDrawer();
    else
        super.onBackPressed();
}


public void start_request()
{
    String pkg = getPackageName();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setComponent(new ComponentName(pkg,pkg+".RequestActivity"));
    startActivity(intent);

    if(DEBUG)Log.v(TAG,"Intent intent: "+intent);
}
}

I am assuming the issue lies within the class above, but for completion's sake, I pasted the two XML files of interest below.

activity_main.xml As you can see, the ImageButton is currently "above" the navigation drawer in hierarchy so as to make it be covered by the navigation drawer. Moving the ImageButton "below" makes the button work properly, but causes it to appear on top of the navigation drawer (and not tinted like the rest of the layout).

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:fontify="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity"
    android:background="@color/myPrimaryColor">

    <View
        android:id="@+id/block1"
        android:layout_height="240dp"
        android:layout_width="match_parent"
        android:layout_below="@+id/toolbar_actionbar"
        android:background="@drawable/block_primary"
        />

    <TextView
        android:id="@+id/title1"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_below="@+id/toolbar_actionbar"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="56dp"
        android:text="@string/title"
        android:textColor="@color/white"
        android:textSize="34sp"
        android:fontFamily="sans-serif"
        />

    <include
        android:id="@+id/toolbar_actionbar"
        layout="@layout/toolbar_default"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        />

    <ImageButton
        android:id="@+id/button2"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="268dp"
        android:src="@drawable/ic_chevron_up"
        android:background="@drawable/fab_simple"/>

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:layout_below="@+id/toolbar_actionbar"
        >

        <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

        <fragment
            android:id="@+id/fragment_drawer"
            android:name="com.onepersonco.iconrequestbase.NavigationDrawerFragment"
            android:layout_width="@dimen/navigation_drawer_width"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            layout="@layout/fragment_navigation_drawer"
            tools:layout="@layout/fragment_navigation_drawer" />
    </android.support.v4.widget.DrawerLayout>
</RelativeLayout>

fragment_navigation_drawer.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>

<!-- Provides a margin at the top of the navigation drawer. -->
<View
    android:id="@+id/navWhiteSpace1"
    android:layout_width="match_parent"
    android:layout_height="64dp"
    android:background="@color/myNavigationDrawerBackgroundColor"
    />


<android.support.v7.widget.RecyclerView
android:id="@+id/drawerList"
android:layout_below="@+id/navWhiteSpace1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:scrollbars="vertical"
android:scrollbarDefaultDelayBeforeFade="0"
android:scrollbarFadeDuration="0"
android:overScrollMode="never"
android:focusable="true"
android:background="@color/myNavigationDrawerBackgroundColor"/>

</RelativeLayout>
Nick Dev

I ran into the same issue when attempting to follow various navigation drawer tutorials online.

What worked for me was using Mike Penz's MaterialDrawer library on GitHub. He has a very simple tutorial in the "readme" file found on the bottom of the page.

Hopefully someone else with a better understanding of Java can explain why your code failed.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Open navigation drawer when options menu button is pressed

From Dev

Unfortunately stopped when button pressed in android navigation drawer

From Dev

When back button is pressed and navigation drawer is open, my app closes instead of closing drawer

From Dev

Close Navigation Drawer on Back Button Pressed in Flutter

From Dev

open navigation drawer when options icon pressed

From Dev

Toggle button not working for navigation drawer for the first time

From Java

How to close navigation drawer when an item is pressed from it?

From Dev

Start Navigation Drawer Activity when a button is clicked

From Dev

Close Navigation Drawer on back pressed

From Dev

The button declared in the frame is not working properly when it is pressed

From Dev

The button declared in the frame is not working properly when it is pressed

From Dev

Toggle Button in Navigation Drawer

From Dev

Bootstrap Navigation Drawer not working

From Dev

What are the guidelines governing back button behavior when using a navigation drawer?

From Dev

Using setSupportActionBar() stops hamburger button when opening the navigation drawer

From Dev

What are the guidelines governing back button behavior when using a navigation drawer?

From Dev

Xcode: Detecting when a navigation controller implemented "back button" is pressed

From Dev

preserve edittext data when navigation back button pressed in android

From Dev

How to make content navigation button (remains pressed when clicked) in Vaadin

From Dev

add actionbar button with navigation drawer?

From Dev

Navigation drawer selector disable not working

From Dev

ScrollView not working with the addition of a Navigation Drawer

From Dev

OnClick for navigation drawer header not working

From Dev

Navigation Drawer list elements not working

From Dev

listview item not working in Navigation Drawer

From Dev

Navigation drawer not working tutsplus tutorial

From Dev

Navigation drawer selector disable not working

From Dev

Android Navigation Drawer onItemSelect not working

From Dev

listview item not working in Navigation Drawer

Related Related

  1. 1

    Open navigation drawer when options menu button is pressed

  2. 2

    Unfortunately stopped when button pressed in android navigation drawer

  3. 3

    When back button is pressed and navigation drawer is open, my app closes instead of closing drawer

  4. 4

    Close Navigation Drawer on Back Button Pressed in Flutter

  5. 5

    open navigation drawer when options icon pressed

  6. 6

    Toggle button not working for navigation drawer for the first time

  7. 7

    How to close navigation drawer when an item is pressed from it?

  8. 8

    Start Navigation Drawer Activity when a button is clicked

  9. 9

    Close Navigation Drawer on back pressed

  10. 10

    The button declared in the frame is not working properly when it is pressed

  11. 11

    The button declared in the frame is not working properly when it is pressed

  12. 12

    Toggle Button in Navigation Drawer

  13. 13

    Bootstrap Navigation Drawer not working

  14. 14

    What are the guidelines governing back button behavior when using a navigation drawer?

  15. 15

    Using setSupportActionBar() stops hamburger button when opening the navigation drawer

  16. 16

    What are the guidelines governing back button behavior when using a navigation drawer?

  17. 17

    Xcode: Detecting when a navigation controller implemented "back button" is pressed

  18. 18

    preserve edittext data when navigation back button pressed in android

  19. 19

    How to make content navigation button (remains pressed when clicked) in Vaadin

  20. 20

    add actionbar button with navigation drawer?

  21. 21

    Navigation drawer selector disable not working

  22. 22

    ScrollView not working with the addition of a Navigation Drawer

  23. 23

    OnClick for navigation drawer header not working

  24. 24

    Navigation Drawer list elements not working

  25. 25

    listview item not working in Navigation Drawer

  26. 26

    Navigation drawer not working tutsplus tutorial

  27. 27

    Navigation drawer selector disable not working

  28. 28

    Android Navigation Drawer onItemSelect not working

  29. 29

    listview item not working in Navigation Drawer

HotTag

Archive