How to add menuItem dynamicaly in sherlockaction bar? - android

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

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.

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

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)

How can I make that an item of Navigation Bottom Bar doesn't bring me a fragment?

When you select an item in the Bottom Navigation Bar provided by Android Studio it displays a fragment. I want to make a logout item that when you select it, it calls a method but don't actually bring me a fragment.
I understand that NavigationUI set up all the configuration of the navigation bar, so when I try to implement navController.addOnDestinationChangedListener() and add my action to my logout item, I think that overrides the nav configuration and I just can't navigate over the items
Does I have to configure by myself and add a listener on every item?
I also want to make that when a confirmation dialog appears when you clicked the logout item, if u select cancel it returns you to the previous state (EX: I'm in Home fragment, if I click on logout item, and I cancel it, it returns me to the Home fragment)
You can enable/disable any menuitem in NavigationView...
NavigationView navigationView= findViewById(R.id.nav_id_in_layout)
Menu menuNav=navigationView.getMenu();
MenuItem nav_item2 = menuNav.findItem(R.id.nav_item2);
nav_item2.setEnabled(false)

Add Button to Title Bar only on one particular activity

I am bulding an android app where I have three separate activities MainActivity, ActivityOne, ActivityTwo.
I have a title bar for all the activities. I am trying to add a Button to my ActivityOne Titile bar but if I add a button it is showing on all the other activities too. How do I make Button only on my ActivityOne title bar ?
Do you user the 'include' variable in your xml ?

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