Disable Menu Button Bringing Up Status Bar On Samsung Phones - java

I am running an app in full screen immersive mode.
On Samsung phones there is a menu button on the device that, when clicked, forces open the status bar at the top. This slides my entire view down and doesn't go away.
How can I prevent the menu click event from displaying the status bar?

Found it, put this in the activity.
#Override
public boolean onPrepareOptionsMenu (Menu menu)
{
return false;
}

Related

How to detect when the system navigation bar appears on full screen mode?

The following code successfully hides the system's navigation bar from the screen. Users can still swipe up to reveal the navigation bar, which will remain on screen for a few seconds, then disappear again.
Is there a callback to detect when the navigation bar appears and disappears, as the user swipes up, and afterwards, when the navigation bar automatically hides?
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
getWindow().setDecorFitsSystemWindows(false);
if (getWindow().getInsetsController() != null) {
getWindow().getInsetsController().hide(WindowInsets.Type.navigationBars());
getWindow().getInsetsController().setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
}
} else {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
);
}
The code below (taken from the docs) seems to detect when the navigation bar is hidden on launch, but not when the user swipes up to reveal it, or when it disappears afterwards.
View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener
(new View.OnSystemUiVisibilityChangeListener() {
#Override
public void onSystemUiVisibilityChange(int visibility) {
// Note that system bars will only be "visible" if none of the
// LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
// TODO: The system bars are visible. Make any desired
// adjustments to your UI, such as showing the action bar or
// other navigational controls.
} else {
// TODO: The system bars are NOT visible. Make any desired
// adjustments to your UI, such as hiding the action bar or
// other navigational controls.
}
}
});
Is there a callback to detect when the navigation bar appears and disappears, as the user swipes up, and afterwards, when the navigation bar automatically hides?
You can't detect that, a user's swipe to show the navigation bar or the status bar isn't a part of your app, it's the system responsibility that runs in a different process than your app's.
Actually your app's window isn't affected on that swipe; and hence the bars are laid on top of your activity (without any extra insets) and that is an evidence that it's related to the system window instead. So, any listener within your app's process/window can't help on that.
Check this answer for more detail.

How to hide the navigation bar and the status bar on Android only when keyboard is shown?

I'm making a custom keyboard for android, full screen, i want to hide the navigation bar and the status bar on Android only when keyboard is shown and then return the same state.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
}
Use the above given code to hide the status bar from the app. Also, don't forget to apply your keyboard visible condition.

Hamburger to arrow animation not working programmatically

I have made a server directory browsing app which would change contents within the Activity itself. I have been adding a feature: Navigation Drawer and handling the Hamburger and Back icon on the Toolbar as follows:
Home directory:
Hamburger icon as the default state.
Would slide the navigation drawer on clicking the hamburger or at a sliding gesture.
No state-change or animation of the hamburger when the drawer is slided.
Animation of Hamburger to Back icon when a directory is chosen.
Any child directory:
Back button from the previous animation whose sole purpose is to go to a parent directory.
Would slide the navigation drawer at a sliding gesture.
No state-change or animation of the Back icon when the drawer is slided using gesture or when it goes into an another child directory of this directory.
Animation of Back Arrow to Hamburger icon when it comes back to Home directory using back icon or onBackPressed.
I am able to get the animation of Hamburger to Back icon using this answer (Code is used verbatim is as below) but wasn't able to get the Hamburger icon again when coming back into the home directory (didn't included that code and went for another approach which is the next part):
ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
float slideOffset = (Float) valueAnimator.getAnimatedValue();
mDrawerToggle.onDrawerSlide(drawerLayout, slideOffset);
}
});
anim.setInterpolator(new DecelerateInterpolator());
// You can change this duration to more closely match that of the default animation.
anim.setDuration(500);
anim.start();
For appropriate switching between Hamburger and Back icons when browsing to and fro from home and child directories, I have used this answer (Code verbatim as below) as a reference and was able to successfully implement it for 1, 2 and 3 features of home and child directories.
private void enableViews(boolean enable) {
if(enable) {
mDrawerToggle.setDrawerIndicatorEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true); // comment this line of code
if(!mToolBarNavigationListenerIsRegistered) {
mDrawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Doesn't have to be onBackPressed
onBackPressed();
}
});
mToolBarNavigationListenerIsRegistered = true;
}
}
else {
// Remove back button
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setHomeButtonEnabled(false); // comment this line of code
// Show hamburger
mDrawerToggle.setDrawerIndicatorEnabled(true);
// Remove the/any drawer toggle listener
mDrawerToggle.setToolbarNavigationClickListener(null);
mToolBarNavigationListenerIsRegistered = false;
}
}
Coming to the issue at hand which is: While browsing directories, of the switching to and fro from Hamburger to Back icon, the animation part is not working at all. But the states of both the icons are successfully changed along with their functionalities. Let me know if you need some more information for troubleshooting.
You can see a working example of navigation drawer activity if you just create a new project, add an activity and use template NavigationDrawer (if you use Android Studio. Otherwise download this repo)
When I want to learn a new layout I just load up the template and then change individual pieces of code until I have what I wanted. This way you can see what does what, what stops working when you delete some line and how things should be done.
I was finally able to solve it, came to know about the behaviour of the ActionBarDrawerToggle in a much deeper way after tinkering it with the default NavigationBarActivity from Android studio.
The overriding of onDrawerSlide of the mDrawerToggle to block the animation of hamburger by the sliding drawer was the cause of the same blocking of animation of hamburger to arrow in the animatior function in the first place. Notice these two lines from the two different pieces of code (didn't include it earlier, but you get the idea):
#Override
public void onDrawerSlide(View view, float slideOffset) {
// blocks the animation
super.onDrawerSlide(view, 0);
}
// from the animator function above
mDrawerToggle.onDrawerSlide(drawerLayout, slideOffset);
Solution: I removed the overrided onDrawerSlide function, but then, the sliding drawer hamburger to arrow animation would come back as well.
Counter-Solution: I also found out the sliding drawer animation of hamburger to arrow happens due to this line: mDrawerLayout.setDrawerListener(mDrawerToggle) which again is a deprecated function. So I just commented out this line and everything is working as expected.

Disabling Contextual Action Bar Crosswalk-Cordova

Contextual Action Bar (CAB) won't disable using Crosswalk as a plugin in Cordova.
Tried everything, starting with the CSS, all the way through HTML & JavaScript, and even MainActivity.java & XWalkCordovaView.java.
I must disable the Contextual Action Bar. It cannot show up. It's messing my entire app. It needs to be gone, completely. Or at least, I settle with not seeing it in my app.
Here are some pictures:
As you see, we need to select text and show that toolbar (the black one, and disable the blue contextbar, prevent it from showing at all). It's not allowing us to use our toolbar. I mean, with Contextual Action Bar, NO WYSIWYG will work nicely.
I even have problems with the arrow select, which I'd like to disable as well, or at least change the color, or not mess up the sidenav.
So, what I tried:
MainActivity.java
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set by <content src="index.html" /> in config.xml
loadUrl(launchUrl);
// disable the context menu and all long clicks
super.appView.getView().setOnLongClickListener(new View.OnLongClickListener() {
public boolean onLongClick(View v)
{ return true; }
});
super.appView.getView().setLongClickable(false);
}
}
From here:
How to disable long-click which opens the Android top menu bar with copy/paste/etc. buttons in Cordova Crosswalk apps?
Pull Request: https://github.com/crosswalk-project/crosswalk/pull/3193
Now, please, I need to disable the Contextual Action Bar when I select some text. Thank you so much in advance. I've searched the whole web and nothing seems to work.
I've filled an issue on Crosswalk Project's Issues:
https://crosswalk-project.org/jira/browse/XWALK-7206

Displaying menu items in the Android ICS action bar

I've got an app that I've written targeting Android 2.1 which makes use of the menu button to expose some options. I'd like to have this menu available through the action bar overflow button in ICS, but I'm having trouble with getting it to show up.
If I change my target API to 15, the legacy menu button in the bottom bar disappears in ICS, but the icon in the top right of the action bar doesn't replace it, so there is no way to access the menu. I've tried adding the showAsAction attribute to the menu items, which did nothing. I'm definitely targeting 4.0.3 in my Eclipse build options.
All I want is for that menu to be accessible somewhere whilst using the ICS Holo theme, but still backwards compatible to older devices. How do I go about that?
Usually you add those Action Items simply by implementing the onCreateOptionsMenu(Menu menu) and adding the android:showAsAction="ifRoom" for the desired items in the menu's XML file.
e.g.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu_save"
android:icon="#drawable/ic_menu_save"
android:title="#string/menu_save"
android:showAsAction="ifRoom|withText" />
</menu>
Did you consider this fact?
Edit:
Here is a simple implemantation which worked for me a while ago:
#Override
public boolean onCreateOptionsMenu(Menu menu){
super.onCreateOptionsMenu(menu);
createMenu(menu);
return true;
}
private void createMenu(Menu menu){
MenuItem mnu1 = menu.add(0, 0, 0, "Logout");
{
mnu1.setAlphabeticShortcut('a');
mnu1.setIcon(R.drawable.icon);
mnu1.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
}
}
I was having this issue 5 minutes ago. Dont know if this can be still helpful, but this is how I got it solved:
Add super.setBooleanProperty("showTitle", true); to your onCreate method
#Override
public void onCreate(Bundle savedInstanceState) {
super.setBooleanProperty("showTitle", true);
super.onCreate(savedInstanceState);
//more code...
This will force the action bar to show and the menu button replacement will be there.
I am targeting android 4 in eclipse. Older devices show the bar as title only and of course are listening to default menu button action.

Categories

Resources