Hide&show action bar on pre-honeycomb devices - android

The action bar can be shown even on pre-honeycomb devices, as shown via the actionbar-compat sample.
I want to be able to hide and show the action bar on demand (programmatically). How do I do that?
The problem is that getting the action bar using the support library returns null. I've also tried to find it using its id and set the visibility to gone, but it just showed a white space instead.

in the end i've used actionBarSherlock.
it has much more features and this requested feature is one of them. maybe the new support library works with this feature , but i've already moved to this solution.

ok , i have a workaround , but it doesn't work for the beginning , meaning that for a very short time , the actionbar will be shown on the beginning.
here's the code i've created to hide the action bar (for pre-honeycomb versions) ,which i've thought of by looking at this post :
ViewGroup decorView = (ViewGroup) this.getWindow().getDecorView();
ViewGroup root = (ViewGroup) decorView.getChildAt(0);
View titleContainer = root.getChildAt(0);
titleContainer.setVisibility(View.GONE);
if anyone knows how to make the action bar hidden on the beginning and choose when to show it , please let me know.
EDIT: btw, if anyone wishes to use a theme via the manifest and uses actionBarSherlock, you could use either "Theme.Sherlock.Light.NoActionBar" or "Theme.Sherlock.NoActionBar" , and if you wish to hide&show in code, simply use getSupportActionBar().hide() and getSupportActionBar().show().

Try this,hide action bar in xml by setting following property in xml for your activity.
`
<activity
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
Hope it helps if not then add a comment and if anything is wrong with my answer please correct me.

Related

Customize the action bar of android app with an image

I am creating an android application and I want to customize the look and feel of the action bar of the application.
For my project I am using actionbar sherlock. Currently my app is looking like this:
I want to remove the logo of the application and also the application title from the action bar and replace it with the following image.
Is there any way to accomplish this. I have read that we have to use the style tag to do this. But since I am new I don't know where to write the style tag and how to implement this. Please help...
EDIT
The width of the new image should be adjustable i.e. my requirement is that its width should cover half of the action bar
All I want to achieve is something like this application which is available in play store.
Just use this line in your onCreate method:
Drawable d=getResources().getDrawable(R.drawable.action_bar_background);
getActionBar().setBackgroundDrawable(d);
That will change the background of your actionbar to whatever image you want.
Of course it is always important to have different sized images for different device sizes.
I hope it helps
Update your AndroidManifest.xml tag to include the :icon attribute.
See the developer docs for more information.
Example:
<application
android:logo="#drawable/my_logo"
....>
</application>
Another nice example, for use with a theme/style can be found here.
To hide the title text shown on the action bar see this post's accepted answer. You'll need to have a custom style applied to the action bar to hide the text. If you also want the icon to be larger than the allowed space, you'll need to also set the background of the action bar as explained by #Eenvincible.
It's also worth noting that you're breaking a lot of Android Design Guidelines. It'd be easier for you and better for your users to simply set the right icon/title and move on with the standard ActionBar look/feel. Worth a look: Android Design Patterns - ActionBar.
What you are seeing is actually the default icon. Replace ic_launcher.png file from the following folders(if it exists there) with your image.
/res/drawable
/res/drawable-ldpi
/res/drawable-mdpi
/res/drawable-hdpi
/res/drawable-xdpi
/res/drawable-xxdpi
Also rename your image file to ic_launcher.png
To edit the text on right of icon, you can use:
getSupportActionBar().setTitle("ANY TEXT HERE");

Smoother transition from fullscreen activity using ActionBarSherlock

I'm developing an Android application which uses ActionBarSherlock (ABS) and needs to work in API >=8. The problem is that some transitions between activities aren't smooth enough.
For example: I have two activities, (A) one which is always fullscreen and (B) another one which isn't fullscreen (status bar and action bar are shown). The transition needed is always from A to B. When it occurs and B activity is loaded, all the content (included ABS) is shown as if the activity was fullscreen and then resizes when the status bar is loaded again.
In some devices this effect is insignificant but in other ones it becomes really annoying and even causes that the user touches the wrong section of the view.
Fullscreen declaration is made via Manifest activity's "theme" property (anything by code). For example:
<activity
android:name = "...."
android:screenOrientation = "portrait"
android:theme = "#android:style/Theme.NoTitleBar.Fullscreen">
</activity>
Searching on the Internet for some solution, I've found two main approaches:
1) To use the Android appcompat library and enabling action bar overlay as mentioned here: https://developer.android.com/training/basics/actionbar/overlaying.html#EnableOverlay.
The problem with this is that the app also uses the HoloEverywhere library and many errors appeared when using HoloEverywhere + appcompat. All this errors were related to duplicated XML elements. I've also checked android-support-v4 library in all projects to avoid errors.
2) Using WindowManager flags and applying top padding to the view: http://nubinewsblog.blogspot.com.es/2009/11/smooth-full-screen-transition.html.
With this approach the transition is perfect. The biggest problem - and the reason I need to ask this - is that I'm not able to apply a top margin to ABS and the status bar is shown over the action bar. I can move down all elements except ABS. I suppose it occurs because ABS uses many fixed dimensions and attributes.
I prefer to use the second way (2) but I can try everything needed to make the transition smoother. Any further implementation details needed can be asked and I'll try to answer ASAP. I'd be very grateful for any info or help provided :-)
Really thanks to all for your time.
PS: I'm currently using and Android 2.3.6 device for testing.
PS: when I say fullscreen I always refer to fullscreen + no status bar + no action bar.
I've solved my problem doing the following:
1.- I have to optimize all the screens where the AB was shown. In some cases I used ListViews which weren't correctly implemented and that caused a noticeable load time in the activity.
2.- I have shown the status bar BEFORE starting the new activity. I mean: I've shown the status bar in the fullscreen activity just before starting the non-fullscreen one. With that I achieved that the layout of the second activity (non-fullscreen) was never resized.
With this two little changes now the AB transition is much more smoother.
I close this question but, if someone has any doubt, I will be pleased to answer it. Last but not least, ¡thanks to all who tried to help with this problem!
the best solution is to clear full screen flags on onPause method of first (full screen) activity
#Override
protected void onPause(){
super.onPause();
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

What layout does the ActionBar use?

I'm trying to do minor tweaks to the layout of items inside an ActionBar, and hitting a lot of problems. It would help if I knew (or even better: could override!) the layout which Android is using for the ActionBar itself.
(Android's layout system doesn't allow you to fully control layout of "items" direct from the item itself - all the options are enabled/disabled based on what type the parent/container layout has)
So, for instance...
try to make a custom ActionView that takes "all remaining space" (because you have no title / don't need a title)
...everything breaks. There are lots of workarounds, all of which have their own bugs (I've tried 3 from SO already, and they all break on different versions of Android / different handsets)
this would be TRIVIAL if I could set the ActionBar's layout to "RelativeLayout" and use "layout_toLeftOf" etc
...but the docs don't seem to answer this, nor do they provide a way of setting it. Any ideas? I don't want to have lots of hardcoded, broken code to workaround the API (because it'll make maintaining this app a nightmare :( )
Have you looked at ActionBarSherlock? It's a support library extension that implements action bar on all versions of Android using single API. Also, when it comes to layouts, I often find it very useful to look at the source code. You can find action bar layouts on the very top of the list here.
Load the view hierarchy and then you will be able to see the views that compose any layout.
http://developer.android.com/tools/debugging/debugging-ui.html

Android Navigation Bar

I've done a great amount of searching and I can't seem to find anything that helps me. I'm new to Android programming (I do know Java though), and I am working on an app that deals with dynamic content being downloaded from a server. I would like to have a bottom navigation bar, that is persistent throughout the app. This nav bar will consist of 5 buttons, that when clicked will open a new activity. However I would like the activity to be loaded in the content area above the nav bar.
So basically I will have a layout that contains a content view and the nav controller. The nav controller should never change...the content view should load a new activity upon nav button click. Does anyone have any ideas? Thanks.
You will have to create a common layout for the navigation bar , and include it in every layout of the activity. use "include" tag in the xml to do this. please have a look at the discussion below, it may help you.
Common buttons or tabs at bottom for every activity
Have a look at this project: http://code.google.com/p/androidtabs/
You might want to consider looking at Fragments since the TabActivity is deprecated. You would need to download a compatibility package in the SDK in order to use it on pre-honeycomb devices. It should be able to do exactly as you want.

Applying a custom title bar for the entire application

I actually want to apply a custom title bar (kind of like the Action Bar), but since i'm developing for Froyo, I actually need to have it in a xml file. The trivial way to do this is to just write the code to create the title bar in each of the activities.
I did search around for some efficient ways and found this on SO
Similar Problem
There are 2 solutions proposed over there, but I am having problems in implementing them.
To include the layout of your title bar in the layout of all the Activities. My question is say I have a sample layout as follows, where should the include tag go and do I need to use Theme.NoTitleBar theme for the application in order to get it working?
To subclass Activity and then derive all of my Activities from that. Should the custom Title bar creation method be defined in the onCreate method of the subclassed Activity. Because if I do this, the custom title bar does appear, but it appears blank. No buttons,etc.. are present on it.
Thanks in advance for any help you provide
The tag belongs inside the top level view container (linear layout/relative layout). Yes use NoTitleBar so you don't have the Android provided title bar in your app window.
There is obviously an issue with your code there, with out any code in your post I cannot help you.

Categories

Resources