How to hide the bottom action bar in Android? - android

I set "android:uiOptions="splitActionBarWhenNarrow" in AndroidManifest.xml.
Therefore, if there is no enough room for the device, the action bar will be split into two parts.
Sometime, I want to hide the action bar by calling getActionBar().hide(). But it will leave an ugly white space in the bottom. How can I get rid of it?
I tried to call getActivity().getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY), but it would block my webview content.

Just a simple work, simply use OverLay. use this in your style
<style name="AppTheme" parent="#style/Theme.AppCompat">
<item name="android:windowNoTitle">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowActionBarOverlay">true</item>
</style>
or if you want to do it by programmatically, just past it before your setContentView() function
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
and give some transparency, so it won't hide the web content. just read the documentation for the style
http://developer.android.com/training/basics/actionbar/overlaying.html

Try to remove android:uiOptions from <application> or <activity> elements from the AndroidManifest. Also, remove the android.support.UI_OPTIONS for activity that need in the AndroidManifest.

the split bar can only be hidden with api 11 for the other i tried on my tablet right now and
it continue to be here on the screen, my tablet have android 4 api >10 then split bar must be taken into count when designing a layout example:
for games touch screen like tablets or phone without harwdware key ,the thouch event x,y must be trasformed to y=y+height of the split bar, becouse the size of the window is fullscreen - splitbar and that make a lot of difference if you have graphical interface drawed with canvas ,that mean you must check if the touch is iniside a rectagle of a screen button.
and use dp pixel and not pure pixel ,all drawing maust use dp converted pixel cordiantes for make sure that have same coridanate system on the screen and on the canvas
px = dp *(dpi * default dpi)
deafult dpi is 160pdi screen medium pixel resolution

Related

Should I hide the android actionbar or try to style it

I am building an app for Android and iOS. It is working but the creative people want to totally change the style so that the top part of the screen (where the actionbar is on android) is taller and has their logo centered in it.
Should I hide the actionbar and put the logo (and custom nav icons) at the top of my layouts, OR should I try to change the style of the actionbar (make it taller and include the logo in the center)? Either option seems a bit painful, but I don't think I can talk them out of it.
you should create own View. You can't center any item (icon, logo, title) in ActionBar, also you can't change height. Android ACtionBar's guidelines are very strict. You might change some params by using "findViewById" and passing hardcoded android ids, but they might change for different device manufacturers resulting no change on these units (or even some crashes)
Personally, I would probably modify the ActionBar and try to maintain as much of the functionality as possible. Especially if this is a long running project and it might go back to the standard action bar later.
You can do this by adding your own custom view that will contain your centered logo to the action bar:
getActionBar().setDisplayShowCustomEnabled(true);
getActionBar().setCustomView(R.layout.action_bar_view);
You can then use the action buttons and home/up buttons as you normally would.
Depending on your needs however, you may find it challenging to keep the logo centered since the home and action buttons will add to the left and right respectively which will shift the center view if unbalanced. If so, you can still use your custom action bar view from above and add buttons directly to it inside a FrameLayout to maintain the centering.
To change the height, you can use themes and styles. Wherever you define your styles, set the actionBarStyle and the height in that style:
<style name="MainTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle">
<item name="android:height">70dp</item>
</style>

Force showing titles with splitActionBarWhenNarrow option enabled

It's typical for android apps that if actionbar takes more than 50% of screen width, it moves menu to bottom of screen. Obstacle is that it removes titles too no matter if they would fit or not.
In screenshot below you see comparison of same app run in 480x854 vs 320x480 screen. You can see that it moves menu in smaller screen but removes titles as well despite of that they would fit fine there.
I'm using ActionBarSherlock. According to it's creator The only way to display both would be to use a custom view in the action item that contained both an icon and text.
Can some of you folks give simple example of how to do this? I'm interested only in forcing showing titles, nothing fancy. There is nothing unusual in my app, but if you need sample source codes, I can provide them for you.
You can see that it moves menu in smaller screen but removes titles as well despite of that they would fit fine there.
AFAIK, the bottom portion of the action bar never shows titles.
Can some of you folks give simple example of how to do this?
Add an android:actionView element to your <item> in your <menu> resource, pointing to a layout file that contains whatever you want your fake menu button to be:
<item
android:id="#+id/add"
android:actionLayout="#layout/add"
android:icon="#android:drawable/ic_menu_add"
android:showAsAction="ifRoom"
android:title="#string/add"/>
In your Java code, after inflating your menu resource, you can call getActionView() on the associated MenuItem to get at this inflated layout and configure its widgets (e.g., call setOnClickListener()). In my case, the widget I want to configure is an EditText:
EditText add=
(EditText)menu.findItem(R.id.add).getActionView()
.findViewById(R.id.title);
add.setOnEditorActionListener(this);
(snippets from this sample project)
Personally, I'd either get rid of the split action bar or leave it display as it does by default.

Tab item width in Action Bar (Android)

I'm using 12 tabs in an Activity, in the Action Bar (target is API 17, tested on Galaxy Nexus 4.2.2).
As expected, I get a horizontall scrolling list of tabs under my action bar. In the screenshot below, you can see that the last tab (B, on the right) is noticably smaller than the other tabs (don't take the "E" tab into account, it can be scrolled as there are 4 more tabs on the left).
You can see from the blue glow that there is nothing more to scroll. I'm using the default Theme.Holo.Light.DarkActionbar, without any custom view yet.
Why is this last tab smaller than the other ? And how can I make sure that it gets the same width as the others ?
Indeed I came accross the same problem and the only work around I found was to disable the dividers between tabs. Looks like there is a bug in the native actionbar that does not take care of the dividers size when measuring tab bar container.
<style name="actionBarTabBarStyle" parent="#style/Widget.Sherlock.Light.ActionBar.TabBar">
<item name="android:showDividers">none</item>
</style>
(Here I'm using actionbarsherlock but it is not the source of the problem you could extend your style from parent="#android:style/Widget.Holo.ActionBar.TabBar")
And apply it in your theme:
<item name="android:actionBarTabBarStyle">#style/actionBarTabBarStyle</item>
If you absolutely need the actionBar divider, one simple solution may be to add it directly to the tab background (left or right)

Custom home button on ActionBar

I am using ActionBar Sherlock library. So, to change the default home button. I did this:
<style name="Theme.mTheme" parent="android:Theme.Sherlock.Light.DarkActionBar">
<item name="android:homeAsUpIndicator">#drawable/custom_home</item>
</style>
which didn't work
So, i added this too:
<item name="homeAsUpIndicator">#drawable/custom_home</item>
now its working. I am having this custom home icon/button on every ActionBar. But in 1 of my Activities i have this in code:
actionBar.setIcon(R.drawable.options_holo_dark);
When i am in that Activity, I can see the icon which i set programatically ie.., options_holo_dark. The 1 which i set in Theme ie.., custom_home is not visible. But the Icon has moved to the Right as if its giving space on the left to the icon i set in theme(though not visible).
This is what i am getting now:
So, how can i avoid that empty space on the left side of the Home Icon?
Thank You
Theme item android:homeAsUpIndicator (and homeAsUpIndicator for ActionBarSherlock) sets drawable for the up icon - that's the little arrow pointing to left that is displayed next to the app icon when you have called setDisplayHomeAsUpEnabled(true) on the action bar.
The size of the up drawable defines the left margin for the app icon (logo). By default its dimensions are 16dp x 16dp. If you put there wider drawable the gap between edge of the screen and the app icon would be wider even though the up icon is not displayed at the moment.
If you want to change the app icon (logo). Use setLogo(int) or setLogo(Drawable) method of ActionBar. Don't forget to call setDisplayUseLogoEnabled(true) too - this method toggles between displaying app icon and custom logo. Also you can define the logo in manifest in attribute android:logo of <application> and <activity> tags and set in theme that you want to use logo instead of app icon in the action bar.

When is the ActionBar with Tabs two lines vs one line layout being used?

I've asked a similar question about the Android ActionBar before: Change ActionBar Tabs background color
I still don't have an answer to the question: when will the two line design/when the one line design used? I've set a custom divider to my tab bar and it's also being used in the horizontal layout. However to create drawables/styles based on the orientation/screen size etc I need to know when which layout is being used. Looking through the Android source it seems they are using the same drawables for both layouts, so that doesn't really help me. The same problem applies when changing the font color of the Tab View.
I fear that it'll be decided in code which format is being used, so there's not really any way around this. Can anyone confirm this? Or is there at least a way to find out in code if the Action bar is one lined or two lined?
Android will stack tabs beneath the action bar when it deems the screen size/orientation to be narrow (like on a normal sized screen in portrait, or on a small sized screen regardless of orientation). Similarly if there are many tabs, in some cases they will appear as a drop-down list in order to ensure the best fit in the action bar.
The Action bar is a highly adaptive UI control. If you are going to use its navigation modes I would strongly suggest not trying to anticipate their configuration or attempt to apply styles that are specific to each one. Your tab drawables will always need to be 9patch anyway because the base action bar height will also vary across orientations and screen sizes (notice its height is slightly smaller in landscape).
That said, you can query the action bar height at runtime using its getHeight() method. This Honeycomb Gallery example included in the SDK uses a bunch of logic in an OnGlobalLayoutListener to ensure that the Fragment layout responds to the various action bar sizes appropriately.

Categories

Resources