I added the action bar tabs programmatically. I do not know how to align the action bar tabs to the right.
ActionBar bar = getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// instantiate tabs
ActionBar.Tab pageTab= bar.newTab().setText(getString(R.string.page))
.setIcon(R.drawable.ic_page);
bar.addTab(pageTab);
// other settings
bar.setDisplayOptions(ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_TITLE);
bar.setDisplayShowHomeEnabled(true);
// remove the activity title to make space for tabs
bar.setDisplayShowTitleEnabled(false);
Action bar tabs appear on the left. The right is used for your options menu and any items from it that you promote to be toolbar buttons.
This has been a while since the original question, but... I needed a solution for the same problem due to visual appearance of the Activity. It turns out that if you append white spaces to either the title or subtitle, the tabs will be moved to the right, so you can do this:
bar.setTitle("Some titile\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
This will shift the whole tab bar to accommodate the space for the white spaces. I must say that this is not an elegant solution but works if you don't have any actions in the action bar. (I didn't check what happens when actions are present.)
I was able to align the actionbar right by customizing my application theme
In my AndroidManifest.xml, I added a android:theme property:
<application
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#style/CustomActionBarTheme">
...
I then added a new themes.xml file to my project, and added :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarTabBarStyle">#style/MyActionBarTabBar</item>
</style>
<style name="MyActionBarTabBar">
<item name="android:gravity">right</item>
</style>
</resources>
The tabs should now be right aligned.
EDIT:
It works only if your actionbar is displayed on 2 lines (in portrait orientation)
Related
First off, I'm not completely sure that Title Bar and Action Bar are the same? 2 different things?
I have an existing application that I need to maintain. In I have an activity that had a custom view as a title. What I want is to have the default title bar for the activity - the native one. I removed the custom view, and in the activity class I removed requestWindowFeature(Window.FEATURE_NO_TITLE); but the activity still doesn't show the Title bar. I've set the activity theme to android:theme="#style/Theme.AppCompat.Light". Still no Title Bar.
The activity intent is started with launchActivityForResult - don't know if that has anything to do with that.
What am I missing here? Is there a way to show it programmatically?
title-bar and action-bar is different thing.
use theme like this.
Theme.AppCompat.Light
instead of
Theme.AppCompat.Light.DarkActionBar
<style name="MyMaterialTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
and add this theme to manifest
<application
android:name="com.qwesys.ecommerce.application.AppController"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="#style/MyMaterialTheme">
First off, I'm not completely sure that Title Bar and Action Bar are the same? 2 different things?
Yes these are 2 different things implementation wise. Action Bar is now deprecated and we use something called the toolbar.
https://developer.android.com/reference/android/widget/Toolbar.html
You can make customized toolbar https://developer.android.com/training/appbar/setting-up.html
And for your second part use startActivityForResult() and like suggested by #sagar above you use the theme to to make the toolbar appear.
I want to put a picture on my action bar, instead of the text (No, I am not using action bar sherlock), and if possible for the action bar to be transparrent AND with detectable height (I have done transparent action bar before, but you can't get its height programatically this way).
It should be in styles somehow, not programatically. Right now I have this styles.xml and it does absolutely nothing...
<resources>
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/AppTheme.ActionBarStyle</item>
</style>
<style name="AppTheme.ActionBarStyle" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:icon">#drawable/img_ab_youlocal_logo</item>
</style>
P.S. YES, I have searched before asking, the other asnwers were not helpful.
If you are using an api < 21 you could do something similar this:
ActionBar actionbar = getActionBar();
actionbar.setDisplayShowCustomEnabled(true);
actionbar.setCustomView(R.layout.someLayoutfile);
You may have to this before the Parent View gets inflated / set via setContentView();
Also in api > 11 you have a logo attribute:
Using a logo instead of an icon
By default, the system uses your application icon in the action bar, as specified by the icon attribute in the
<application> or <activity>
element. However, if you also specify the logo attribute,
then the action bar uses the logo image instead of the icon.
A logo should usually be wider than the icon, but should not include unnecessary text.
You should generally use a logo only when it
represents your brand in a traditional format that users recognize. A
good example is the YouTube app's logo—the logo represents the
expected user brand, whereas the app's icon is a modified version that
conforms to the square requirement for the launcher icon.
i'm using actionbarsherlock for my actionbar. I have a sliding menu and searchview. when the application get launches, it will automatically pick the up navigation icon from style.xml file.
When the search menu gets expanded, the up navigation icon will not get changed, it will be still looking like 3 line slider menu. How to change the up navigation icon when searchview is expanded?. I have represented the flow in below image.
Create custom back button theme with parent of your custom theme.
<style name="MyThemeForSearch" parent="#style/MyCustomTheme">
<item name="android:homeAsUpIndicator">#drawable/my_back_indicator_for_search</item>
</style>
Set theme in runtime when Search is expanded., i.e onClick
setTheme(R.style.MyThemeForSearch);
check your layout drawable's whether you have set an image like 3 liner slide menu
when you create navigation drawer it automatically sets default image which will be loaded representing 3 liner slide like you mentioned change your ic_drawer.png image and replace image with what icon you wish.
also you might go check changing your theme
> <style name="Theme.MyFancyTheme" parent="android:Theme.Holo">
> <item name="android:homeAsUpIndicator">#drawable/my_fancy_up_indicator</item>
> </style>
I wanna remove the app icon from my action bar
I dont want the home icon there, I want to make more room for my other icons :) Now 4 of them are aligned to the right and the fifth one only shows up on the bottom when I press the settings key
I found this answer which looks promising
Open your styles.xml file and add below codes in your Actionbar style
<item name="android:displayOptions">showHome|homeAsUp|showTitle</item>
<item name="displayOptions">showHome|homeAsUp|showTitle</item>
<item name="android:icon">#android:color/transparent</item>
Problem is, I dont know what do they refer to as "your Actionbar style"
EDIT:
after having read some answers here is what I did to my manifest
<application
android:allowBackup="true"
android:debuggable="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock.Light"
android:theme="#style/CustomActionBarTheme" >
and at the last line I get this error:
Attribute "theme" bound to namespace "http://schemas.android.com/apk/res/android" was already specified for element "application".
and this is my styles.xml:
<style name="CustomActionBarTheme">
<item name="displayOptions">showHome|homeAsUp|showTitle</item>
<item name="android:icon">#android:color/transparent</item>
</style>
Also I've tried
mActionBar.setDisplayHomeAsUpEnabled(false);
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowTitleEnabled(false);
mActionBar.setDisplayUseLogoEnabled(false);
mActionBar.setHomeButtonEnabled(false);
It only makes the home icon invisible but it is still taking the space. Why have they provided 5 non-working methods here, what is the point? Why does it have to be so frustrating.
I worked around this issue in the following way:
- removed my settings icon
- then made my Home icon look like a settings icon
Now I have to find a way to make the Home icon open up the navigation drawer
And I also have to find a way to remove the huge blank space on the right side of the Home button so my icons are evenly spread.
I have added ActionBar tabs to my application. Default color for that underline is light blue. How do I change that color or style for selected tab ?
For anyone wants to change actionbar color/background in code, you can do something like this
final ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.action_bar_bg));
To change the tab bar color under the actionbar:
actionBar.setStackedBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.color_brown_dark)));
To change tab bar background:
actionBar.setStackedBackgroundDrawable(getResources().getDrawable(
R.drawable.coupon_header));
This may give some clues Action Bar Style Gen
selectableItemBackground is the attribute I think your looking for.
I'd recommend you read this article about Customizing the Action Bar as well as look at this question on SO and this one as well.
In code i cant seem to find a way to customize the individual item selected but , customizing the bar itself would look something like this.
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable("FF0000"));
ActionBar bar = getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// set background for action bar
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0c2354")));
// set background for action bar tab
bar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#B5C0D0")));
bar.show();
Here is a much easier way:
I've been struggling with this for days, but finally found the solution. I'm using AppCompat. You can set colorAccent in your theme and that will change the highlight color on your ActionBar. Like so:
<item name="colorAccent">#color/highlightcolor</item>
Here it is in context:
<style name="LightTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/darkgrey</item>
<item name="colorPrimaryDark">#color/black</item>
<item name="colorAccent">#color/highlightcolor</item>
</style>
Where I originally posted this answer: Android Tab underline color not changing
1) Generate the Action Bar Style, click Download ZIP to get the files
2) When you extract the zip file created in Step 1, you will get a res folder. Add this folder to your project under platform/android.
3) Modify manifest.xml to Use the New Action Bar Style, where "Action" is name of your style set in step 1.
<android xmlns:android="http://schemas.android.com/apk/res/android">
<tool-api-level>14</tool-api-level>
<manifest>
<application android:theme="#style/Theme.Action"/>
<uses-sdk android:minSdkVersion="14"
android:targetSdkVersion="16"/>
</manifest>
</android>
This manual helped me and I hope it will help you too.