How to add Action bar to main screen when using navcontroller? - android

I am creating a project in which i would like to have following phenomenon. The first activity can be launched from an intent. When it is launched it has a back button on action bar. There are further destinations from this activity which i have set up using navcontroller. I have set up actionbar with navcontroller. But it removes the back button from main screen . What should i do to achieve desired result?

Try to enable the back button on action bar in your main activity:
supportActionBar?.setDisplayHomeAsUpEnabled(true)

Related

Why action bar didn't show up after calling the show Unit?

I have 2 formats of action bar, I want to hide home action bar when I am in detail page and want to hide detail action bar when I am in home page. When I start the app, it directs me to home page and it shows me home action bar without showing detail action bar as I expected. I click something on home page that directs me to detail page and when I am on detail page, it also shows detail action bar without showing home action bar as I expected. But trouble comes when I get back to home page again using up button, it doesn't show the home action bar. So the home page doesn't have any action bar displayed. Why using show() doesn't bring back the home action bar?
I would suggest to change from relying on the detail fragment to set the home activity's action bar and instead rely on the home activity to set its own action bar.
For example:
In the onPause() of the home activity, you could add
supportActionBar?.hide().
Then in the onResume() of the home
activity you could add the line supportActionBar?.show().
Try that out and see if that works.

Drawer icon requires 2 clicks to open drawer

I have previously used Android Studio's wizard to implement the Master-Detail pattern, and tried to convert the Detail to have a drawer instead of the "up" button.
I went in AndroidManifest.xml and removed the "parent" attribute on the Detail's activity settings, but it still didn't work.
Then I realized that in my Detail Activity's onOptionsItemSelected function, I had forgotten to delete this:
if (id == android.R.id.home) {
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// to navigate up one level in the application structure. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
NavUtils.navigateUpTo(this, new Intent(this, SongListActivity.class));
return true;
Now it sort-of works, but I have to click the navigation drawer icon 2 times. This is the "navigation drawer icon" I'm referring to:
I noticed that when I click on an item in the Master list, it launches the Detail activity, and it seems to not be in focus. The Navigation bar is not visible at first. This is what I mean by saying "Navigation Bar":
When I click the Navigation Drawer Icon once, the Navigation bar shows up. When I click it again, then the drawer will open.
How do I get it so the new activity is already in focus as soon as it's launched, so I only have to click the Navigation Drawer Icon one time?
Edit: I noticed if I try to click anything in the Action Bar, it takes 2 clicks. I tried several other apps on my Android and they don't have this problem. Usually, they start out with the Navigation Bar already there. Maybe I have some code hiding the Navigation Bar, making the Action Bar not be in focus?
I just looked through my code, and realized that I had forgotten to delete rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); from before. It was in my onCreateView method of my DetailFragment class. I commented it out, and the problem was immediately fixed.

How to add menuItem dynamicaly in sherlockaction bar?

So I've been working on and Android app that has a Sherlock action Bar on the top and that part is working fine but now I want to be able to dynamically add Menu Items to the Sherlock Action Bar.
I have to display log in name on screen if user is log in.
Suppose on Activity A I have Log in Button. When that button is clicked then LoginActivity starts. After log in B activity is start. If user pressed back button from activity B then Activity A again starts. But menu items name is not displays. For that I am using onCreateOptionsMenu method.
Maybe this should help you:
What onPrepareOptionsMenu do?
i.e., use onPrepareOptionsMenu() method

How to switch between splitActionBar and default ActionBar in Activity having multiple fragments

I have one activity which has two fragments.
I have defined following option for the activity in manifest file-
android:uiOptions="splitActionBarWhenNarrow"
I want the action bar at bottom for one fragment and at top for another fragment.
How can I do this?
The action bar is tied to the activity, not the fragments. If you need a bar with buttons somewhere in the middle of your activity, you'll have to add something yourself. Perhaps a button bar that is styled to look like an action bar.

ActionbarSherlock On navigating to new activity home icon change

As in new action bars, when user clicks on any activity on dashboard, app will take user to new activity, at the same time along with home icon in action bar there would be an arrow showing this activity been started from other activity. How to get this feature with Sherlock android bar?
home icon in action bar there would be an arrow showing this activity been started from other activity
That is not what that arrow means. That arrow means that you are giving the user an option of moving "up" a navigation hierarchy, in addition to the BACK button offering navigation back to the preceding activity. This is described in greater detail in the Android Design documentation.
How to get this feature with Sherlock android bar?
The same way you do with the native action bar: call setDisplayHomeAsUpEnabled(true) on the ActionBar.

Categories

Resources