As i mentioned in title of question I want to completely remove title from actionbar but at first run (when I run it from eclipse) title shows for a while and it's not what I want
in the onCreate method I've add this 2 line of code and its work but LATE!!
getSupportActionBar().setTitle("");
getSupportActionBar().setDisplayShowTitleEnabled(false);
may this 2 pics help u understand me
Set your theme to 'no action bar' in your manifest, then apply your normal theme in code after set contentview!
android:theme="#style/Theme.Sherlock.Light.NoActionBar"
and then.
this.setTheme(R.style.myTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
While your code hides actionBar Title, the title will still be displayed while your activity is loading and before you remove the title in your code.
I think a better solution if you want to remove title from actionbar in all of your activities from the start is to do it by setting a theme and override the actionbar style.
To do this you have to create a style in your styles.xml and use this as your application theme e.g.
<style name="AppTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/AppTheme.ActionBarStyle</item
<item name="actionBarStyle">#style/AppTheme.ActionBarStyle</item>
</style>
<style name="AppTheme.ActionBarStyle" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="android:titleTextStyle">#style/AppTheme.ActionBarStyle.TitleTextStyle</item>
<item name="titleTextStyle">#style/AppTheme.ActionBarStyle.TitleTextStyle</item>
</style>
<style name="AppTheme.ActionBarStyle.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textSize">0dp</item>
<item name="textSize">0sp</item>
<item name="android:textColor">#00000000</item>
<item name="textColor">#00000000</item>
</style>
or another example:
<style name="AppTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="android:actionBarStyle" tools:ignore="NewApi">#style/AppTheme.ActionBarStyle</item>
<item name="actionBarStyle">#style/AppTheme.ActionBarStyle</item>
</style>
<style name="AppTheme.ActionBarStyle" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="android:displayOptions" tools:ignore="NewApi">useLogo|showHome</item>
<item name="displayOptions">useLogo|showHome</item>
</style>
These Code samples were taken from some of my projects where i use actionbarsherlock so you may have to edit it according to your needs.
Hope it helps.
Related
I am wanting to customise the rows of the overflow menu in the action bar. I found a great blog post explaining how to go about doing this, which seem simple enough. The link is below.
http://scriptedpapers.com/2014/08/12/android-action-bar-overflow-menu-customization/
I am specifically wanting to change the background colour of the overflow menu rows so the theme that I am using looks like the following:
<resources>
<!--the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/CustomActionBar</item>
<item name="android:homeAsUpIndicator">#drawable/upcaret</item>
<item name="android:actionOverflowButtonStyle">#style/CustomOverflowButton</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item>
</style>
<!--ActionBar style -->
<style name="CustomActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/customBlue</item>
</style>
<style name="CustomOverflowButton" parent="#android:style/Widget.Holo.Light.ActionButton.Overflow">
<item name="android:src">#drawable/overflowbutton</item>
</style>
<style name="PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#color/customBlue</item>
</style>
Applying this theme to the application, the background colour of the overflow menu remains the same colour as the default for Holo.Light.DarkActionBar, despite setting a custom popupMenuStyle.
For my project, the minSdkVersion is 15 and targetSdkVersion is 19.
Does anyone have any ideas?
Thanks.
Try specifying a 9-patch drawable instead of a color.
Go here and choose the color that you want your rows to be by selecting a color from the "Popup color" drop-down.
The only file you need from the zip is menu_dropdown_panel.9.png.
Make sure to place this file in your various drawable-xxxx folders.
Then use it like this:
<style name="PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#drawable/menu_dropdown_panel</item>
</style>
If it still doesn't work, add this to the above:
Add this line to your main theme (CustomActionBarTheme):
<item name="android:actionBarWidgetTheme">#style/PopupWrapper</item>
Then add this:
<style name="PopupWrapper" parent="#android:style/Theme.Holo">
<item name="android:popupMenuStyle">#style/PopupMenu</item>
</style>
I'm trying to tweak my app with some custom colors but I cannot change the text color of the action bar.
This is how it is currently showing:
If you look close you might see letters in the white tab bar. I'm trying to change this color to black without changing anything else of the action bar.
This is how my styles.xml looks like:
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
<style name="ActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/default_green</item>
<item name="android:backgroundStacked">#color/stacked_white</item>
<item name="android:backgroundSplit">#color/sa_green</item>
</style>
Any help is appreciated.
You can make your custom theme here:
http://jgilfelt.github.io/android-actionbarstylegenerator/
Which includes all tabs and other component.
Try this ...
This should be in the theme
<item name="actionBarTabTextStyle">#style/tabtextcolor</item>
<item name="android:actionBarTabTextStyle">#style/tabtextcolor</item>
This should be where you define the tab text color.
<style name="tabtextcolor" parent="#style/Widget.Sherlock.ActionBar.TabText">
<item name="android:textColor">#android:color/white</item>
</style>
How can I remove line or divider between action bar and main screen?
How can I change the color of this divider in android?
Thanks in advance.
Simply insert the attribute windowContentOverlay to your theme. It's way too simple this way.
<style name="AppTheme" parent="android:Theme.Holo.Light">
<!-- Customize your theme here. -->
<item name="android:windowContentOverlay">#null</item>
</style>
After more effort I can find my ideal Theme.
First of all i must say that Theme.Holo.Light has a shadow in bottom of action bar if you want to have not that shadow you must use Theme.Holo.
After you change the style you must change other settings for yourself like the code.
<resources>
<style name="AppTheme" parent="android:Theme.Holo">
<item name="android:actionBarStyle">#style/AppTheme.ActionBar</item>
<item name="android:background">#ff0000</item>
<item name="android:colorBackground">#ff0000</item>
</style>
<style name="AppTheme.ActionBar" parent="android:Widget.ActionBar">
<item name="android:background">#ff0000</item>
</style>
</resources>
This below code is for my last challange that I found how to resolve it.
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/AppTheme.ActionBar</item>
<item name="android:background">#ff0000</item>
<item name="android:colorBackground">#ff0000</item>
</style>
<style name="AppTheme.ActionBar" parent="android:Widget.ActionBar">
<item name="android:background">#ff0000</item>
</style>
</resources>
Below Image is for first Code, If you notice there isn't any divider.
And below Image is for second Code.
None of these solutions worked for me. I ended up adding this code to the onCreate() event of my MainActivity:
actionBar = getSupportActionBar();
actionBar.setElevation(0);
On Kotlin, you can use supportActionBar?.elevation = 0f to remove the shadow of the ActionBar.
Add this code to the onCreate() function of the desired activity. For example:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Hide ActionBar shadow
supportActionBar?.elevation = 0f
}
The ?. operator controls Null Pointer Exception if you have no ActionBar on this Activity.
Note: If you are not using AppCompat, call actionBar?.elevation = 0f instead.
If you use AppCompat you need set parent="Theme.AppCompat", not "Theme.AppCompat.Light" (the same stands for ActionBar) :)
For example:
#style/MyActionBar
true
#style/MyActionBar
true
<style name="MyActionBar" parent="Base.Widget.AppCompat.ActionBar">
<item name="android:background">#android:color/transparent</item>
<!--For compatibility-->
<item name="background">#android:color/transparent</item>
</style>
This worked for me:
I just added the following line of code to the onCreate() method
getSupportActionBar().setElevation(0);
In your styles.xml file , look for your AppTheme style and add the following style into it
<item name="android:actionBarDivider">#android:color/transparent</item>
like this
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:fontFamily">#font/roboto</item>
<item name="android:actionBarDivider">#android:color/transparent</item>
</style>
what it actually does is that it sets the background of the divider between activity window and action bar as transparent.
In case you are using AppBarLayout nothing of that will help. I found the solution using :
AppBarLayout appBarLayout = findViewById(R.id.app_bar_layout);
appBarLayout.setOutlineProvider(null);
I've trying to work around this on the actionbar but from What I can see the title is basicly a TextView but I need to place an image instead of plain text. I try to set it up into the Style themes.xml as this:
<item name="android:actionBarStyle">#style/MyActionBar</item>
And then I defined this style
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/action_background</item>
<item name="android:titleTextStyle">#style/ActionbarTitleStyle</item>
</style>
I thought that I could defined the background for the title but even If I do is not what I want, try the getActionBar().setCustomView(layout); but happend that my actionbar is null before the setContentView is being called and I need it in a Base class.
PD. I only need to care about HONEYCOMB and Higher, so if you please not suggest Sherlock or Jonhanilson implementations.
if you want an image, you can specify the app logo along with the icon (it will be used instead of icon):
<application
android:icon="#drawable/ic_launcher"
android:logo="#drawable/logo"
android:label="#string/app_name"
android:name=".AppName"
>
Now you have an arbitrary image instead of your lanucher icon. What you need to do next is to get rid of the text. In your styles do something like:
<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="titleTextStyle">#style/NoTitleText</item>
<item name="android:titleTextStyle">#style/NoTitleText</item>
<item name="subtitleTextStyle">#style/NoTitleText</item>
<item name="android:subtitleTextStyle">#style/NoTitleText</item>
</style>
<style name="NoTitleText">
<item name="android:textSize">0sp</item>
<item name="android:textColor">#00000000</item>
</style>
You should use both item name="titleTextStyle" and item name="android:titleTextStyle" if you use ActionBarSherlock if I remember well.
Override setContentView like this:
#Override
public void setContentView(int resLayoutId) {
super.setContentView(resLayoutId);
// TODO Set your actionbar changes here
}
OR, you can do this:
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/action_background</item>
<item name="android:titleTextStyle">#style/ActionbarTitleStyle</item>
<item name="android:displayOptions">showCustom</item>
<item name="android:customNavigationLayout">#layout/custom_nav_layout</item>
</style>
Many of my questions about "styling" actionbar tabs were answered by adamp in this thread on tab style, but I am still struggling with my arriving at the desired presentation.
Specifically, I am attempting to do what adamp suggested in the following fragment from my styles.xml file, but, I cannot get the inherited (Widget.holo.actionbar) feature of a light blue line to appear under the selected tab nor is there any indication of selection:
<style name="MyTheme" parent="android:style/Theme.Holo">
<item name="android:actionBarStyle">#style/CustomActionBar</item>
</style>
<style name="CustomActionBar" parent="android:style/Widget.Holo.ActionBar">
<item name="android:actionBarTabTextStyle">#style/customActionBarTabTextStyle</item>
<item name="android:actionBarTabStyle">#style/customActionBarTabStyle</item>
<item name="android:actionBarTabBarStyle">#style/customActionBarTabBarStyle</item>
</style>
<style name="customActionBarTabTextStyle" parent="#style/CustomActionBar">
<item name="android:textColor">#2966c2</item>
<item name="android:textSize">20sp</item>
<item name="android:typeface">sans</item>
</style>
<style name="customActionBarTabStyle" parent="#style/CustomActionBar">
<!-- <item name="android:background">#drawable/actionbar_tab_bg</item> -->
<item name="android:paddingLeft">20dp</item>
<item name="android:paddingRight">20dp</item>
</style>
<style name="customActionBarTabBarStyle" parent="#style/CustomActionBar">
<item name="android:paddingLeft">240dp</item>
</style>
Can someone explain why the thin blue line selection behavior of the Honeycomb Gallery Sample App does not work for me?
New insight since this was written: the problem here, I think, is that the style I have created to overide ActionBarTabStyle is entirely bogus:
<style name="customActionBarTabStyle" parent="#style/CustomActionBar">
<item name="android:paddingLeft">20dp</item>
<item name="android:paddingRight">20dp</item>
</style>
I need to specify the correct parent of this style per "Theme.holo"....how can one find where the default style is so it can be specified as a parent?
Thanks
To specify the correct parents for actionbar style in API 11, Check doc here:
https://developer.android.com/training/basics/actionbar/styling.html