Add Button to Title Bar only on one particular activity - android

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 ?

Related

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 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 show the title in Fragment but hide in the Activity?

I have a Activity and it has include more than one fragment.
I know it can use requestWindowFeature(Window.FEATURE_NO_TITLE); to hide the title in Activity.
But I don't want to hide title for all fragment.
Can I hide the title for preference fragment ?
Based on what you say, you will have to use more than one activity. For the fragments that are in a same activity, the title bar is either shown or hidden.
Do not use requestWindowFeature(Window.FEATURE_NO_TITLE); We can get actionBar and hide it after setContentView
When active fragment, show action bar
When fragment detach , notify activity and activity can hide the action bar
Above is my current implement and seems work. Still testing :-D
Simple sample here - https://bitbucket.org/jimmy64/fragmentsample

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.

Android Static title bar

I am trying to create an app that when you click through each page of the app the title bar doesn't move. I can create an xml with the same title bar but every time you go on to a new page the title bar disappears for a second and then reappears with the new page.
Does anybody have any suggestions/code that can help me with this?
Many Thanks
Take a look to Fragments. If you implement "each page of the app" as a separate Fragment - instead of Activity - then you can embed and switch these Fragments into the layout of the main Activity, obtaining what you need.
Use a tabActivity and have the activities inside it.
hide the tab bar as given here tab bar hiding issue android
Use mTabHost.setCurrentTabByTag to set the tab

Categories

Resources