Handler for ActionBar MenuButton click - java

Even after a long search on this subject I came to no result. So I want to ask here.
In my Android application, I try to set a onClick listener for the menu button in the upper right corner (on the actionbar). When the button is pressed, the NavigationDrawer should open. (I have seen this in an app. Unfortunately, I do not know how this app is called.) I do not want to open the menu.
I have already tried:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
android:onClick="showdrawer">
<item />
</menu>
with
public void showdrawer(View v) {
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLayout.openDrawer(Gravity.LEFT);
}
...but nothing happens when I press the button.
Is there a way to implement this?
I would be very grateful for help.

In my Android application, I try to set a onClick listener for the menu button in the upper right corner (on the actionbar).
First, there is not necessarily a "menu button in the upper right corner (on the actionbar)" on all devices, when using the stock action bar implementation. It will depend upon API level of the device and whether the device has an off-screen MENU key.
Second, that is for the overflow. Please leave it alone.
Third, you have no direct access to that button anyway.
When the button is pressed, the NavigationDrawer should open
The navigation drawer is usually opened by tapping on the left side of the action bar, on the app icon, particularly when it has the "mini-hamburger" on the left edge. That is handled for you via ActionBarDrawerToggle, if you are using DrawerLayout for the navigation drawer.
It is possible to have a right-hand drawer as well, though I seem to recall Google advocating that more for contextual operations. They do not cover this in the written design guidelines, but I seem to recall seeing it on an Android Design in Action video. For that, you might use your own regular action item in the action bar as a trigger, if the right-hand drawer is for activity-level contextual operations.

Related

Youtube like scrolling behaviour

I have Frame Layout(Each Containing RecyclerView), Bottom Navigation Bar and a Custom toolbar.
I want that for each Fragment whenever their is some upward scrolling event occurs, my toolbar should hide and whenever comes back whenever down scrolling event occurs.
Can you help to do this as I am new to Android Programming.
Check This or This.
These questions answer the problem of hiding the bottom bar.

Android Dev: Navigation View vs App Bar

I'm new to Android development. I get that a NavigationView is an AppBar (i think). What makes these two different? I want to create a custom "appbar/toolbar" with a centered logo and menu/settings button in the top right corner (instead of the standard left) which reveals a drawer.
I was going to ditch the built in appbar/toolbar all together and just create my own somehow and include button overlay which displays a drawer.
What would you do? Navigation view, app bar, or custom toolbar from scratch? I don't know what the standard is or what is acceptable. What is the difference between a navigationview and appbar. Thank you.
edit: I'm slowing realizing that an appbar is one feature within a navigation view, among others like a drawer layout, menu items etc... i think.
1. NavigationView
By using NavigationView, we can bind the menu directly with NavigationView. This is the benefit of the NavigationView. No need to create ListView and adapter with navigation drawer. By default we can get selector of item click. With menu we can change the color of icon of selected menu.
For more details :
1.https://developer.android.com/reference/android/support/design/widget/NavigationView.html
http://www.technotalkative.com/part-4-playing-with-navigationview/
2. AppBar
Appbar is for toolbar with scrolling effect. We can easily give the material design effect.
For more details :
1.https://developer.android.com/reference/android/support/design/widget/AppBarLayout.html

Appending extra toolbar in fragment view

In my application on the dashboard, there is an application bar that looks something like the image below.
As shown in the image, I have a toolbar that currently shows the Navigation drawer.
From the navigation drawer, I can navigate to a fragment A that replaces the TAB area under the toolbar as shown in the image below.
Is there any way I can add two toolbars like this where I can show the navigation drawer icon and back button together inside a fragment?
There is no best way to achieve what you are looking for, considering it goes against the Android Design Guidelines. Although not explicitly stated, the navigation drawer icon and the back button icon are never displayed together.
The theory behind this design is that navigation should be intuitive and predictable, displaying two navigational icons next to each other detracts from an intuitive user interface. The back button should be displayed if there is something to go back to. Though, the need for persistent navigation can be addressed in two different ways. Take Google's Gmail app for example.
By default the NavigationView supports using a swipe from the left edge of the screen as a gesture to open the navigation drawer. In the Gmail app, the navigation drawer icon is show while you are in any one of your inboxes. As soon as a message is selected, the navigation drawer icon is replaced with the back button. Though, you will notice that you can still access the drawer using the gesture stated previously.
On larger screens, the Gmail app supports a miniature navigation drawer. This drawer can remain in view without the need to display to navigational icons. Though this is a little more difficult to implement with the current support library, if you are looking to, this answer may help.
Finally, to answer your question, there is no built-in way to display a back button and a navigation drawer icon together. If you need to do so, the only way would be to use a "work-around", as you currently are.
Though, the only change I would probably make is to use an ImageButton rather than an ImageView. Then you can set the style of the button using style="?android:attr/actionButtonStyle" to mimic the look of an ActionBar button.
Just to update, for the time being, to achieve the above what I have done is.
I added a layout to my fragment file where I draw a custom back button like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimaryDark20"
android:orientation="horizontal"
android:padding="15dp"
android:weightSum="3">
<ImageView
android:id="#+id/backButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:layout_weight="0.2"
android:src="#drawable/delete_icon" />
</LinearLayout>
When a person clicks on backImage, I call popBackStack.
imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
getFragmentManager().popBackStack();
}
});
The above code gives me the desired functionality.
Note, for the above to work you need to make sure you are adding your fragmentTransaction to backstack as below
final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.home_content_layout,NAME_OFYOUR_FRAGMENT,"nameOfYourFragment");
transaction.addToBackStack(null);
transaction.commit();

Android UX flow, next button on ActionBar

I am in a UX flow conundrum. In the ActionBar http://developer.android.com/design/patterns/actionbar.html, I am tasked to place a 'Next' button similar to that in iOS.
I am aware that Android has no equivalent button for that, is there a suggestion?
I would say it depends on your needs. Generally apps with a need for a Next button put it somewhere near the bottom-right of the screen.
I would personally be against putting it on the ActionBar as some devices handle it differently. Older devices might end up putting it behind the Menu button, and you'd have to be careful not to let it go into the overflow '...' menu as it may be too hidden-away in there (again, depending on your use case).
The other thing to remember is that putting it on the right of the Action Bar suggests that the button on the left of the Action Bar is a 'back' button, which is is not (It's an 'up' button).
I'm thinking more something like this:

Drop down menu from action bar - allowing drag and drop icons to be drawn to screen

as the title suggests I'm trying to add code to my app which allows the user to click on an item in the action bar menu which then unfolds a drop down menu (spinner class?) containing a few options such as lamp, tv etc. - each with an icon. The user will then be able to select one of these and drag and drop the icon (or an image representing the icon) to the canvas where it is then drawn. What is the best way to go about this?
If you're referring to the ActionBar overflow menu items, then you would have to take a look at the code for the ActionBar in the framework and extend it in your application, but that would firstly require quite a hassle and secondly would break compatibility when changes are made to the ActionBar in new versions of Android.
Also, this goes completely away from what the ActionBar is intended to be. You should only have actions in the overflow menu, not contain elements that directly interact with the Activity content. It's just wrong. Consider redesigning your UI so that you implement the requested featured inside the content view, not on the ActionBar.

Categories

Resources