how to keep full screen when keyboard popup - android

I am working on my full-screen project recently, and it's implemented by Immersive mode. It works fine and correctly except one part:
As keyboard popping up, hiding status bar will also shows up.
How can I get rid of it? I want status bar keep hiding when I click edittext in my layout.
here's my code:
int flag = View.SYSTEM_UI_FLAG_LOW_PROFILE
|View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|View.SYSTEM_UI_FLAG_FULLSCREEN
|View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDecorView = activity.getWindow().getDecorView();
mDecorView.setSystemUiVisibility(flag);
mDecorView.setOnSystemUiVisibilityChangeListener(
new View.OnSystemUiVisibilityChangeListener() {
#Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0) {
mDecorView.setSystemUiVisibility(flag);
}
}
});
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if ((visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0) {
mDecorView.setSystemUiVisibility(flag);
}
}
It must have some walk-around solution. I've seen that some app hide status bar well even when keyboard popup.
Any ideas how to solve this?

you must use <ScrollView> as main layout. example:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
....
</ScrollView>
or use this code in AndroidManiFest.xml:
<activity
android:windowSoftInputMode="adjustNothing">
</activity>

Related

Status bar background stays on screen when entering immersive mode?

I've been searching everywhere but I'm at a loss about that : trying to activate immersive mode on a project;
Nearly everything works fine, except the background of my status bar always stays there, spoiling the immersion...
I have included a screenshot of the screen before and after activating the immersive mode, and set the "colorPrimaryDark" to full green for max contrast :
screenshots showing the background of the status bar when nothing should be there
The code I used and reinserted in a blank project to isolate this problem comes straight from the google dev examples, in my MainActivity, I have :
private final String TAG = "DEBUG::" + this.getClass().getSimpleName();
private final int INITIAL_HIDE_DELAY = 1500;
private View decorView;
private Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//setting needed decorView for fullscreen behavior
decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener(onSystemUiVisibilityChangeListener);
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
Log.i(TAG, "onWindowFocusChanged::hasFocus = " + hasFocus);
if (hasFocus) {// When the window gains focus, hide the system UI.
delayedHide(INITIAL_HIDE_DELAY);
} else {// When the window loses focus, cancel any pending hide action.
mHideHandler.removeMessages(0);
}
}
private void hideSystemUI() {
Log.i(TAG, "hideSystemUI");
int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
uiOptions |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
uiOptions |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
uiOptions |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
uiOptions |= View.SYSTEM_UI_FLAG_FULLSCREEN;
uiOptions |= View.SYSTEM_UI_FLAG_LOW_PROFILE;
uiOptions |= View.SYSTEM_UI_FLAG_IMMERSIVE;
decorView.setSystemUiVisibility(uiOptions);
}
private final Handler mHideHandler = new Handler() {
#Override
public void handleMessage(Message msg) {
hideSystemUI();
}
};
private void delayedHide(int delayMillis) {
Log.i(TAG, "delayedHide");
mHideHandler.removeMessages(0);
mHideHandler.sendEmptyMessageDelayed(0, delayMillis);
}
private View.OnSystemUiVisibilityChangeListener onSystemUiVisibilityChangeListener =
new View.OnSystemUiVisibilityChangeListener() {
#Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
// The system bars are visible
getSupportActionBar().show();
delayedHide(INITIAL_HIDE_DELAY);
} else {
// The system bars are NOT visible
getSupportActionBar().hide();
}
}
};
I wonder if my problem might come from layout or style files, but those are raw from project generation...
I hope someone out there can point me to where I failed!
Thanks in advance!
EDIT : I found that removing : android:fitsSystemWindows="true" from my activity's layout file allows a real fullscreen mode, but then, my ActionBar is partly hidden behind the StatusBar -when showing. Could it be that when I set my getSupportActionBar().show(); in onSystemUiVisibilityChangeListener, it gets drawn too soon?
EDIT 2 : How I understand this so far is that I only have 2 choices regarding the position/size of my content (action bar included) :
top of the screen, which will show the actionBar partially hidden by the statusbar,
or below the statusBar's bottom, which will leave me with a "hole" when the statusBar is hidden -_-
I am now looking for a solution to animate the ActionBar off-screen/on-screen by myself inside my onSystemUiVisibilityChangeListener method, but can't find a way to grab its View to do so, solutions posted there https://stackoverflow.com/a/21125631/6463888 seem out of date...
I met the same problem today. But I didn't solve this issue by setSystemUiVisibility. I solve it using following method:
hide:enter full screen
mActivity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
show:normal display
mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
So,
the way I solved this may seem a bit stretched, but I'm only a beginner, so feel free to comment!
I don't use getSupportActionBar().show(); or getSupportActionBar().hide(); anymore, but I managed to grab the View that contains the ActionBar which is an AppBarLayout, and I animated this View instead. So I call a small function animateActionBarInOrOut to animate it on or off screen inside onSystemUiVisibilityChange :
private void animateActionBarInOrOut(boolean appears){
Log.i(TAG, "animateActionBarInOrOut::actual position = " + toolbar.getY());
if(appears){
toolbar.animate().translationY(48).alpha(1); // move it out of the screen
}else{
toolbar.animate().translationY(-48).alpha(0); // move it out of the screen
}
}
Although this is not exactly an answer to the initial question, it works as a solution to the problem, one just has to move the content accordingly...
Hi your problem is caused by StatusBar nature, it has a separate layout from your main content and you need to set his color manually. For example when you call onSystemUiVisibilityChange() you can take the color of your background and, after set the color of StatusBar with that color. This is a workaround to avoid 2 different background colors.

Toolbar overlay hidden under system UI in YouTube player fullscreen

I'm using a YouTubePlayerFragment in my activity, and attempting to overlay the player with an app bar (aka action bar) when the player is in fullscreen. I'm following the guidelines and example in the YouTube Player API "Overlay ActionBar Demo" sample application and YouTubePlayerFragment documentation (more detail below).
All of this worked fine when I was extending from Activity and using the core ActionBar. But when I switch to using AppCompatActivity with the support Toolbar, a few issues arise:
The Toolbar is laid out under the status bar and navigation bar
The player no longer plays when the Toolbar is on top of it
It seems as though the player fullscreen mode used to treat the action bar as part of the system UI (along with the status bar and navigation bar), in terms of positioning and overlay, but no longer does so with the Toolbar.
Any thoughts on why this is happening or how I can use the Toolbar to properly overlay the YouTube player in fullscreen mode? I realize the Toolbar is just another view and I could probably force it to resize and reposition under the status bar, and I could set up a listener for system UI changes and show and hide my Toolbar accordingly, but I'm hoping there's a cleaner fix that I'm missing.
Here's a screenshot:
More detail: I was able to reproduce this behavior in the "Overlay ActionBar Demo" sample app (ActionBarDemoActivity), with the following changes:
Extend AppCompatActivity
Change import from android.app.ActionBar to android.support.v7.app.ActionBar
Add Toolbar to layout
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<view
class="com.examples.youtubeapidemo.ActionBarDemoActivity$ActionBarPaddedFrameLayout"
android:id="#+id/view_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
...
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="#color/material_deep_teal_500" />
</FrameLayout>
Change the theme to Theme.AppCompat.Light.NoActionBar and add windowActionBarOverlay
<style name="OverlayActionBarTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
</style>
Set the Toolbar as the action bar in onCreate()
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Note that the sample app also does the following (I didn't change these):
Implement YouTubePlayer.OnFullscreenListener
Extend the layout and set padding when not in fullscreen so that content displays below Toolbar
#Override
public void onFullscreen(boolean fullscreen) {
viewContainer.setEnablePadding(!fullscreen);
...
}
public static final class ActionBarPaddedFrameLayout extends FrameLayout {
public void setEnablePadding(boolean enable) {
paddingEnabled = enable;
requestLayout();
}
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int topPadding =
paddingEnabled && actionBar != null && actionBar.isShowing() ? actionBar.getHeight() : 0;
setPadding(0, topPadding, 0, 0);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
Set YouTube player fullscreen control flag
player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT);
Handle config changes
<activity
...
android:configChanges="keyboardHidden|orientation|screenSize"
...
</activity>
I suspect this is a bug. I filed a new bug report for the layout problem, and added a comment to an existing report about the support ActionBar/Toolbar being treated as an illegal overlay.
Toolbar overlay hidden under system UI in YouTube player fullscreen
With AppCompat theme on older devices, ActionBar is detected as an illegal overlay
In the meantime, as a workaround I'm doing the following:
Layout issue
As Troy suggested, I added android:fitsSystemWindows="true" to the Toolbar XML. This fixed the layout in fullscreen, but caused padding to be added to the Toolbar when leaving fullscreen (screenshot). I added logic to the onFullscreen(boolean) method to remove the Toolbar padding (toolbar.setPadding(0, 0, 0, 0)) but this unfortunately still shows white space in place of the padding, which disappears when the layout is next redrawn (e.g., when clicking an item, starting the player, etc). I'm still a little stumped on how to properly set the layout/padding, but the current workaround will do for now.
Illegal overlay issue
Given that showing the Toolbar will pause the YouTube player in fullscreen, I've added logic to only show the Toolbar when the player is already paused. This isn't ideal, as it forces the user to pause the player to see the Toolbar, but it's the best option I can think of.
In onFullscreen(boolean), if we enter fullscreen and the player is playing, the Toolbar is hidden.
public void onFullscreen(boolean isFullscreen) {
mFullscreen = isFullscreen;
if (isFullscreen && youTubePlayer.isPlaying()) {
toolbar.setVisibility(View.GONE);
}
else {
toolbar.setVisibility(View.VISIBLE);
}
}
When setting up the player (in onInitializationSuccess()), I added a listener to show and hide the Toolbar on play and pause:
youTubePlayer.setPlaybackEventListener(new YouTubePlayer.PlaybackEventListener() {
...
#Override
public void onPlaying() {
if (mFullscreen) {
toolbar.setVisibility(View.GONE);
}
}
#Override
public void onPaused() {
if (mFullscreen) {
toolbar.setVisibility(View.VISIBLE);
}
}
});
This code will solved your issue.
To hide navigation bar and toolbar
public void fullScreenCall() {
if(Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { //lower api
View v = getActivity().getWindow().getDecorView();
v.setSystemUiVisibility(View.GONE);
} else if(Build.VERSION.SDK_INT >= 19) {
//for new api versions.
View decorView = getActivity().getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
}
}
to back normal mode
public void normalScreenCall() {
if(Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
View v = getActivity().getWindow().getDecorView();
v.setSystemUiVisibility(View.VISIBLE);
} else if(Build.VERSION.SDK_INT >= 19) {
//for new api versions.
View decorView = getActivity().getWindow().getDecorView();
decorView.setSystemUiVisibility(0);
}
}
Try adding android:fitsSystemWindows="true" to your toolbar in your XML file.

Hide status bar in android when is softkeyboard visible but without using fullscreen flags

I need to create activity which will contain text input (EditText) and some list of items (TextView-s) under that input. The status bar wont be visible, only navigation bar will be visible. After user clicks on EditText, soft keyboard needs to be displayed, but system UI cant be changed (status bar invisible, navigation bar visible). User has to be still able to scroll to the bottom of ListView (to be able to see the last item in the ListView), while softkeyboard is still visible.
The problem is that I am not able to achieve this behavior - status bars stays hidden only if I use flag WindowManager.LayoutParams.FLAG_FULLSCREEN. But in that case content of activity wont be resized and keybord will cover few TextView-s at the bottom of ListView. I found many similar questions here, but none of them describes my situation (invisible status bar + visible soft keyboard + visible all layout content of activity).
It seems that when is keyboard displayed, android will change some flags of UI, so I tried to reset them back afterwards, but without success - see usage of method "hideStatusBar()".
Here is my code:
Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="EditText"/>
<ListView
android:id="#+id/test_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
Activity:
public class TestActivity extends Activity {
private ListView listView;
private ArrayAdapter<View> adapter;
private List<View> views = new ArrayList<>();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_content);
adapter = new ArrayAdapter<View>(this, 0, views) {
#Override
public View getView(int position, View convertView, ViewGroup parent) {
return views.get(position);
}
};
listView = (ListView) findViewById(R.id.test_list_view);
listView.setAdapter(adapter);
TextView textView = null;
for (int i = 0; i < 50; i++) {
textView = new TextView(this);
textView.setText("textView - " + i);
views.add(textView);
}
final View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
#Override
public void onSystemUiVisibilityChange(int visibility) {
hideStatusBar("onSystemUiVisibilityChange");
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
hideStatusBar("onSystemUiVisibilityChange (delayed)");
}
}, 500);
}
});
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
hideStatusBar("onWindowFocusChanged");
}
public void hideStatusBar(String place) {
Log.i("test", "hideStatusBar - " + place);
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN ;
decorView.setSystemUiVisibility(uiOptions);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
Activity definition in AndroidManifest.xml:
<activity
android:name="TestActivity"
android:label="#string/app_name"
android:windowSoftInputMode="stateHidden|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Edit:
I was probably not clear enough.
This is what looks like my layout without displayed soft-keyboard:
img1
This is what it looks like after soft-keyboard is displayed and line "getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);" is commented: img2. Status bar is visible (that is the problem) and you can scroll to the last item in ListView.
If I add flag "WindowManager.LayoutParams.FLAG_FULLSCREEN" to the window, status bar becomes transparent but still visible and you cant sroll to the last item in ListView: img3
I tried to find answer here but everyone suggests to use fullscreen layout by one of following ways
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
or using fullscreen theme
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
or by setting window flags
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Each of these solutions have one problem: keboard is displayed above/over the layuout and that is why it is not possible to scroll to the last item in ListView.

Hide the navigation buttons causes a move in the surfaceView and bad response in rapid touch

I'm develop a video Streming app. I want to hide navigation bottons but SurfaceView position is translated from actual center to the new center.
I read about Using Immersive Full-Screen Mode but i want app work in android 4.0+. And Immersive is only for 4.4.
Furthermore, if i touch rapidly, hidding don't work fine. If I use Visibility.GONE versus Visibility.SYSTEM_UI_FLAG_HIDE_NAVIGATION hidding work fine (rapidly touch), but re-center problem persists.
Re-center movements problem occurs both with GONE and SYSTEM_UI_FLAG_HIDE_NAVIGATION.
SurfaceView is anchored to center:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/Black">
<SurfaceView
android:id="#+id/videoSurface"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<LinearLayout android:orientation="horizontal"
android:id="#+id/channelList"
android:background="#2000"
android:paddingLeft="5.0dip" android:paddingTop="5.0dip" android:paddingBottom="5.0dip" android:layout_width="wrap_content" android:layout_height="80.0dip">
<!-- Inserted dynamically -->
</LinearLayout>
</RelativeLayout>
The Java Activity relevant Code:
public class VideoActivity extends Activity {
...
//Prepare Screen (FULLSCREEN)
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
...
mVideoSurfaceView = (SurfaceView) findViewById(R.id.videoSurface);
mVideoSurfaceView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View paramAnonymousView, MotionEvent paramAnonymousMotionEvent) {
Log.d("UiVisibility", "onTouch");
VideoActivity.this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
return false;
}
});
// Synchronize the other elements (from android docs)
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener (new View.OnSystemUiVisibilityChangeListener() {
#Override
public void onSystemUiVisibilityChange(int visibility) {
Log.d("UiVisibility", "onSystemUiVisibilityChange - bool " + String.valueOf((visibility & View.GONE) == 0));
// 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_HIDE_NAVIGATION) == 0) {
// TODO: The system bars are visible. Make any desired
// adjustments to your UI, such as showing the action bar or
// other navigational controls.
VideoActivity.this.findViewById(R.id.channelScroll).setVisibility(View.VISIBLE);
getActionBar().show();
} 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.
VideoActivity.this.findViewById(R.id.channelScroll).setVisibility(View.GONE);
getActionBar().hide();
}
}
});
}
I have solved the issue:
In Activity I define:
private static int LAYOUT_FLAGS= View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
private static int HIDE_FLAGS=LAYOUT_FLAGS |View.SYSTEM_UI_FLAG_FULLSCREEN
|View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
LAYOUT_FLAGS sets the layout as if the status bar and navigation bar are hidden. And makes the inner layout will not move when the bars are hidden or shown.
HIDE_FLAGS Makes effective the hiding.
In onCreate()
...
//Prepare Screen (FULLSCREEN)
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
...
//onClick - Hide System UI (Only for hidden, show events are handler by the system)
mVideoSurfaceView = (SurfaceView) findViewById(R.id.videoSurface);
mVideoSurfaceView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.d("UiVisibility", "onClick");
hideUI();
}
});
//Synchronize my bars with System UI hidding
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener (new View.OnSystemUiVisibilityChangeListener() {
#Override
public void onSystemUiVisibilityChange(int visibility) {
Log.d("UiVisibility", "onSystemUiVisibilityChange - bool " + String.valueOf((visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0));
// 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_HIDE_NAVIGATION) == 0) {
// The system bars are visible. Make any desired
// adjustments to your UI
VideoActivity.this.findViewById(R.id.channelScroll).setVisibility(View.VISIBLE);
//getActionBar().show();
mIsListChannelVisible=true;
} else {
// The system bars are NOT visible. Make any desired
// adjustments to your UI.
VideoActivity.this.findViewById(R.id.channelScroll).setVisibility(View.GONE);
//getActionBar().hide();
mIsListChannelVisible=false;
}
}
});
Show and hide methods:
// Hide need a delay to wait nav bar transition is completed. (fix: too fast click fails)
private void hideUI(){
mVideoSurfaceView.getHandler().postDelayed(new Runnable(){
#Override
public void run() {
VideoActivity.this.getWindow().getDecorView().setSystemUiVisibility(HIDE_FLAGS);
}
},600);
}
private void showUI(){
VideoActivity.this.getWindow().getDecorView().setSystemUiVisibility(0);
}
My custom bar is covered by the navigation bar, to fix it:
In myLayout.xml set fitSystemWindows=true
<HorizontalScrollView
android:fitsSystemWindows="true"
android:id="#+id/channelScroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true" >
It works perfect.

onSystemUiVisibilityChange not called after screen rotation

I'm trying to have a fullscreen app, with the navigation bar disapearing after few seconds and reappearing on user interaction (like the Android 3d gallery video player behaviour) for Android 4.2.2 (API 17)
To achieve this, i'm using this code :
public class MainActivity extends Activity {
private View mRootView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// OnCreate code ...
mRootView = getWindow().getDecorView();
setOnSystemUiVisibilityChangeListener();
showSystemUi(false);
}
private void showSystemUi(boolean visible) {
int flag = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
if (!visible) {
// We used the deprecated "STATUS_BAR_HIDDEN" for unbundling
flag |= View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}
mRootView.setSystemUiVisibility(flag);
}
private void setOnSystemUiVisibilityChangeListener() {
mRootView.setOnSystemUiVisibilityChangeListener(
new View.OnSystemUiVisibilityChangeListener() {
#Override
public void onSystemUiVisibilityChange(int visibility) {
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
showSystemUi(false);
}
}, 2000);
}
});
}
As you can see, i've been inspired by the Android API and the android 3d gallery code : http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/4.2.2_r1/com/android/gallery3d/app/MoviePlayer.java#MoviePlayer.setOnSystemUiVisibilityChangeListener%28%29
So, here is my problem :
This code works greatly if i don't move the device.
But if i made a screen rotation, the navigation bar will not be displayed, clicking on screen will display it, but the callback onSystemUiVisibilityChange seems to be never called (checked with debugger), so the navigation bar will never disappear. And if i rotate the screen again, it will works again. (In fact, it seems like it only works if i rotate the screen while the navigation bar is displayed)
Does anyone has an idea of where this problem comes from ?
Thx.

Categories

Resources