I know that it is possible to add a Back Button to a Title Bar in an Android app, by setting:
<activity
android:name=".MyActivity"
...
android:parentActivityName=".SomeActivity"
... />
in AndroidManifest.xml.
Is it also possible to add an arbitrary button with some functionality in the Title Bar?
If YES, what is the way to do it?
Related
I have used Theme.AppCompat.Light.NoActionBar in my styles.xml to remove the action bar in my Android application. In all activities, I'm including a toolbar instead.
I am using a third party library (http://kokum.io) for user login in the app. I do not have control over the activity XML or code for the login screen that the library uses for authentication. The top of this activity is going behind the status bar.
Is it possible to make the activity show up below the status bar without access to the activity code/XML?
I figured out the solution.
In AndroidManifest.xml we can specify themes specifically for each Activity.
<activity
android:name="io.kokum.integration.LoginActivity"
android:theme="#style/CustomTheme" />
This can override the app level theme specifically for this activity.
In the specific case above, I was able to use a theme that provides an action bar to fix the issue.
Hey all I'd like help in creating my app in android studio I am new to this so I'll do my best to try and help you all understand best into what I am trying to do.
I am going to post two pics of how my design should look and I can't seem to get the start of the title bar done. In android studio it always on all of the project start-ups puts a black title bar with a picture of an android and its all black id like it to be cleared of the photo and re colour'd into red and the title text center'd as in my design image.
any help would be much appreciated
this should show the two pictures of my design
While you can edit the xml to change the ActionBar, your best bet is going to be using the new Toolbar. A toolbar is a fully customizable ActionBar without a lot of the traditional constraints of it. You can treat the toolbar just like any other layout container and include layout elements inside like TextViews, etc.
After you have designed your toolbar in xml, you can simply set the toolbar to be your action bar by calling activity.setSupportActionBar(yourToolbar);
This is much more flexible and allows much more control over the look and feel than using the traditional action bar.
Action bar custom label
AndroidManifest.xml:
<activity
android:name="com.package.app.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You can change the android:label from your app name to your desired title for each activity you have.
Action bar background color
To change the action bar background, create a custom theme for your activity that overrides the actionBarStyle property. This property points to another style in which you can override the background property to specify a drawable resource for the action bar background.
Styling the Action Bar
The title of my SplashActivity is quite long, so appears truncated beneath the launch icon on the device's home screen.
I want a shorter title shown beneath the launch icon, but a longer title shown in the Activity's action bar.
So, to try and achieve this I have specified a shorter title in the manifest...
<activity
android:name=".SplashActivity"
android:label="#string/app_name_short"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...and I'm using...
setTitle(getString(R.string.app_name));
...in the onCreate() method of SplashActivity so that the full title appears in the action bar.
It works, but only after about a 1 second delay. (So when SplashActivity is displayed, it shows the short title for 1 second before changing to the longer title.)
Is there any way I can fix this or any known workaround?
I've also tried creating a PreSplashActivity (with a short title) as the launch activity, including code to immediately launch SplashActivity (with a long title), but PreSplashActivity is still displayed for 1 second (even though it doesn't call setContentView(), so I'm a bit stumped.
Any ideas?
In this post answered by mark Renouf made it know that intent-filters can have a label attribute If it's absent the label is inherited from the parent component
Have you looked at the new docs for API21, specifically Toolbar? http://developer.android.com/reference/android/widget/Toolbar.html
With the new Toolbar you include it in your layout file like any other view. A nice side effect of this is that the initial screen is blank and the action bar appears in sync with the rest of your content. This gives you the option to set the title and make any customizations necessary before it becomes visible.
Here's details about using AppCompat to support older versions, it includes a section on using Toolbar in your layout and setting it as the action bar: http://android-developers.blogspot.ie/2014/10/appcompat-v21-material-design-for-pre.html
In my Android app I'm setting the title for an Activity using android:label in the AndroidManifest.xml. But now I want to display different titles in the Menu Bar (when the app is opened) and for the caption under my icon on the Homescreen. Is there any way to achieve this using xml? Or do I have to set the title for the Startscreen icon in the xml and have to set the title displayed in the ActionBar using Activity.setTitle() ?
The text under the icon on home screen is defined by android:label in <application> element in your manifest xml.
The same android:label exists for each activity in <activity> element. This will set the text in the action bar/title bar for each activity separately.
<application
android:label="#string/home_screen_app_name"
<activity
android:name=".main"
android:label="#string/main_activity_title">
</activity>
</application>
I found a question that does answer mine: How to set different label for launcher rather than activity title? Short, the answer is to set the label attribute in the intent
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to hide the title bar for an Activity in XML with existing custom theme
i remove the action bar by
requestWindowFeature(Window.FEATURE_NO_TITLE);
however, when the app starts, the action bar appears in a very short time before it executes the above statement.
how can I make it totally disappear?
thank
I've noticed that if you set the theme in the AndroidManifest, it seems to get rid of that short time where you can see the action bar. So, try adding this to your manifest:
<android:theme="#android:style/Theme.NoTitleBar">
Just add it to your application tag to apply it app-wide.
You can set it as a no title bar theme in the activity's xml in the AndroidManifest
<activity
android:name=".AnActivity"
android:label="#string/a_string"
android:theme="#android:style/Theme.NoTitleBar">
</activity>