I'm currently android application. In this application, I've added following line to hide topbar of android.
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
In this case, when users want to enter setting of my apps in phone, they can press "menu" button of Android phone. But for Samsung Galaxy tab2 7.0, there is no menu button in it. That's why I want to know how can I detect current access device is tablet or not in my apps. If tablet, I want to display toolbar of Android in my apps.
Your Galaxy Tab is running Honeycomb or higher, which means that the old Options Menu has been deprecated in favor of Action Bar. That having been said, there's still a menu icon in the title bar (a square with a slash through it in Honeycomb and three square dots in Jelly Bean). If your user clicks that, they get your standard options menu (without menu item icons, however).
The alternative is to run ActionBar Sherlock to give your apps action bars, regardless of OS version.
If you insist on doing your own branching based on OS version, try this:
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.HONEYCOMB)
{
// Gingerbread and earlier
}
else
{
// Honeycomb and later
}
Related
Is it possible to permanently hide Navigation/Status Bar under Android 4.2.2
This solution seems not working under Jelly Bean.
I have GalaxyTab 3 (10.1) and hidding of Status Bar has no effect.
It's hidden on application Start on every screens, but i can expand it.
Problem occurs also after rooting device.
Somebody has faced it before (there is also video how to fix it):
forum.xda-developers.com/showthread.php?p=37466852
So my question is:
Is there any way to do this on application level?
Chris Banes and Roman Nurik have develop this usefull tool to controls the System UI easily
https://gist.github.com/chrisbanes/73de18faffca571f7292
No, it seems like there is no way to do this for your entire application on tablets running 4.+. Also, fully disabling it so it never appears is NOT possible.
However, the solution you linked does sort of work for Android 4.2.2, (tested on Nexus S and 10 inch tablet on emulator) but even when it works it reloads the status bar if certain user interactions occur to allow navigation (for example, pressing the menu button on a phone). So this means you should plan on spamming the flag every now and then.
I personally tried with this code in my oncreate:
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
// Remember that you should never show the action bar if the
// status bar is hidden, so hide that too if necessary.
ActionBar actionBar = getActionBar();
actionBar.hide();
Which resulted in:
With the 4.2.2 phone the actionBar below also disappears, this does not seem to be possible for tablets.
Coming from the Android documentation about hiding the status bar, it seems that on Android 4.0 or lower, you would be able to set the fullscreen flag for the entire application and be done with it, but this has been changed to the piece of code above.
Next, the UI documentation has this to say:
The SYSTEM_UI_FLAG_LOW_PROFILE flag replaces the STATUS_BAR_HIDDEN flag. When set, this flag enables “low profile" mode for the system bar or navigation bar. Navigation buttons dim and other elements in the system bar also hide. Enabling this is useful for creating more immersive games without distraction for the system navigation buttons.
So I guess it could be that the galaxy tab 3 requires some playing around with these kinds of flags and does not support actually hiding the status bar but rather prefers making it "less visible" ...
Finally, the setSystemUiVisibility method has some great examples if you're still interested in making sure the status bar stays hidden throughout your application.
Please note, that the status bar and the navigation bar are two completely different things. The navigation bar contains the back, home, and recent apps buttons, while the status bar contains the notifications, clock, battery, etc... The status bar can be easyly hidden with flags like SYSTEM_UI_FLAG_FULLSCREEN, but more convenient, using this as your app base theme:
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
In tablets, the navigation bar often consists the status bar, so if the navbar is visible, the status bar will be too. You can't just hide the status bar, because then you would have to hide the nav bar too.
The purpose of you can't hide the navigation bar forever, is that the user must be able to control his device and navigate as he wants to.
You can't hide the navigation bar before 4.0, and as in the developer guide says, you can hide the nav bar with the SYSTEM_UI_FLAG_HIDE_NAVIGATION flag, however, it won't stay hidden once the user touches the tablet. More explanation here: Android Developers - Hiding the Navigation Bar
In 4.4 KitKat, a new API was introduced, the immersive mode, with that you can hide the navigation bar and still make the user to be able to interact with your app, without the navigation bar revealing itself. The user can swipe down from the bottom of his screen to make it visible again, this clears the SYSTEM_UI_FLAG_IMMERSIVE flag. If you want to make the navigation bar disappear when the user doesn't interact with it, then you can use the SYSTEM_UI_FLAG_IMMERSIVE_STICKY flag, so it will disappear if the user finishes with it. More explanation here: Android Developers - Android 4.4 API
Also immersive tutorial: Android Developers - Using Immersive Full-Screen Mode
Also, make sure you are targetting the API 19, and only use this flag, when your app runs on API 19 or later. More on checking API version: Here (StackOverflow)
Hiding the Status Bar under Android 4.2.2 (SDK 17)
This solution worked for me.
getWindow().getDecorView().setSystemUiVisibility(8);
try this..its working for me..
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,windowManager.LayoutParams.FLAG_FULLSCREEN);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.about_app_phone);
}
From the article "Say Goodbye to the Menu Button "
it seems now the menu button is going to the action bar.
"If you’ve already developed an app to support Android 2.3 and lower,
then you might have noticed that when it runs on a device without a
hardware Menu button (such as a Honeycomb tablet or Galaxy Nexus), the
system adds the action overflow button beside the system navigation. "
But since I do not want the action bar takes the space, and I only need one menu button there, I hope I had a menu button within the navigation bar at the bottom.
How to do that?
[Update] From one aplication's code, it seems if I set the target level is lower, and use the add menu function, the menu button can be put with the navigation bar at the bottom. But anyway, as Samus Arin said, if there is only button for the menu, it doesn't make sense to build a action bar.
You can develop for newer releases, and then detect if there is a menu-button on the device. If there is not, show your own in the UI.
http://developer.android.com/reference/android/view/ViewConfiguration.html#hasPermanentMenuKey()
Ex.
if(ViewConfiguration.hasPermanentMenuKey(context)){ Has menu-button } else { Does not have menu-button, show in UI }
As you said, if you want the overflow-button in the navigation-bar you have to set the target-sdk to 13 or lower.
IMO this option should be given to the developer regardless of targetsdk.
UPDATE: hasPermanentMenuKey() can only be used in SDK>13, so you have to check this manually in your code.
I have an application which runs full-screen and relies on the menu button. What I didn't realise is that devices like the Galaxy Tab use an actionbar which no longer has a menu button. My app currently loads a fragment displaying a settings menu when one touches the menu button:
#Override
public boolean onPrepareOptionsMenu(Menu menu) {
FragmentManager lFM = getSupportFragmentManager();
SettingsDialogFragment lSettingsDialog = new SettingsDialogFragment();
lSettingsDialog.show(lFM, "Settings");
return false;
}
I understand it is possible to add a custom icon to the action bar which when pressed could result in the same behaviour as a menu button. What I am unsure about is how to implement this.
How do I know that a device doesn't have a menu button and I need to add an icon to the action bar? It can't be as easy as checking the SDK version as apparently the actionbar was introduced in honeycomb, but my Galaxy Note runs ice cream sandwich and doesn't have an action bar (it still has a menu button). I don't want to give up any real-estate so adding buttons or menu options to my main layout isn't an option.
I just read on google developer that:
Navigation Bar New for phones in Android 4.0, the navigation bar is
present only on devices that don't have the traditional hardware keys.
It houses the device navigation controls Back, Home, and Recents, and
also displays a menu for apps written for Android 2.3 or earlier.
So I tried setting the target version on my app to 8. Instead of a menu I get a button allowing me to change the screen size of my app - but no menu button.
I have an application which runs full-screen and relies on the menu button.
That has been a bad idea for two years.
What I didn't realise is that devices like the Galaxy Tab use an actionbar which no longer has a menu button.
Such devices have been around for two years.
My app currently loads a fragment displaying a settings menu when one touches the menu button
That was never an appropriate design move. Please allow the MENU button, where it exists, to behave normally, displaying an options menu on Android 1.x/2.x and triggering the action bar overflow on Android 3.0+.
How do I know that a device doesn't have a menu button
http://developer.android.com/reference/android/view/ViewConfiguration.html#hasPermanentMenuKey()
My app has an extended menu and has been working on all legit devices from Android 2.1 up thru 4.1. For R11+, to save screen space, I do not display the Action Bar on "normal" screens, but do on "large" and "xlarge". With the Action Bar present, the menu icon is on the Action Bar in the upper right corner; on normal-size screens, without hardkeys, it is at the lower right in the bar with the Home and Back buttons. This is functioning as expected on the latest phones and tablets.
Now I've had two customers with some sort of direct-from-China-on-eBay 7" tablet running Android 4.0.4 who are not seeing either the Action Bar or the menu icon in the Home/Back bar. I see two malfunctions here: first, that it must be reporting its screen as "normal" since it's using the "NoActionBar" theme; and secondly that it's not then showing the menu icon in the bottom bar. The users state that this device has access to Google Play, so I assume it's an approved device.
Has anyone run into anything like this? The only solution I can see -- since I don't want to activate the Action Bar on everyone's smartphone -- is to add a settings option to display the Action Bar. Any other ideas?
How do you show an options menu on Honeycomb, or an ICS tablet, without an action bar?
After some playing around, it seems there is no way to have an options menu on Honeycomb devices if there is no action bar and targetsdkversion is >=11. Even if your theme is Theme.Holo.NoActionBar. The only way I can see to show an options menu on Honeycomb with targetsdkversion>=11 is with a theme that does have an action bar, and then hiding it in onCreate.
The only way I can see to display the older panel menu on Honeycomb is with targetsdkversion<=10.
In summary, in Honeycomb, there is no way to have an options menu if you don't have an action bar, unless you target below 11. This seems like a bug. In ICS and up you can
have whatever options menus you like, regardless of if you actually have an action bar.
My original goal was to be able to use both the old style panel menu, and new Action Bar menu (in different activities) on Honeycomb and up, while using the panel menu everywhere below Honeycomb.
The reason is there is one activity where it is a requirement to have large menu buttons, however the rest of the app can be perfectly Holo-ed.
To achieve this, I have used Theme.Holo (for api 11+) everywhere except for this one activity where I use Theme.NoTitlebar. I have android:minSdkVersion="5" android:targetSdkVersion="14", so the support menu key doesn't show (and thus doesn't waste screen space on some new HTC phones). I provide my own button to pop up the panel menu if the device doesn't have a hardware menu button (via http://developer.android.com/reference/android/view/ViewConfiguration.html#hasPermanentMenuKey() )
The problem is, this didn't work on a Honeycomb tablet (Galaxy Tab, Honeycomb 3.2). The normal activities with the action bar work fine, but on the special activity nothing happens when I press the menu button (the one I've provided in the UI).
This works fine on at least 2 ICS phones and the emulator (with and without a hardware menu key). Normal action bar menus everywhere except on this one activity, where I get the large panel menu.
So what is the solution? Is this a problem with the Galaxy Tab or with Honeycomb? Is there a different theme I should be using to provide the panel menu?
Edit: I obtained an ICS tablet for more testing, and found the panel menu didn't appear there either. So the exact same app, on the same version of Android, will show a panel menu on a phone and nothing on a tablet. Huh?
Below is an extract from the PhoneWindow system class as for Honeycomb and above Android versions. It is really hardcoded check for Android target version and device screen size. Would you be able to avoid this check - the menu would be displayed normally. But there is no such possibility. That is why it is impossible to show options menu on Honeycomb+ devices with target sdk set to value above 10. It is funny, that in case action bar menu could be displayed, it will be displayed earlier and this code will never be reached. Because of this, the comment above the code looks especially derisively.
// Don't open an options panel for honeycomb apps on xlarge devices.
// (The app should be using an action bar for menu items.)
if (st.featureId == FEATURE_OPTIONS_PANEL) {
Context context = getContext();
Configuration config = context.getResources().getConfiguration();
boolean isXLarge = (config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) ==
Configuration.SCREENLAYOUT_SIZE_XLARGE;
boolean isHoneycombApp = context.getApplicationInfo().targetSdkVersion >=
android.os.Build.VERSION_CODES.HONEYCOMB;
if (isXLarge && isHoneycombApp) {
return;
}
}