Windowsoftinputmode="Adjustresize" Not Working with Translucent Action/Navbar

windowSoftInputMode=adjustResize not working with translucent action/navbar

You are missing the following property:

android:fitsSystemWindows="true"

in the root RelativeLayout of the fragment .xml layout.

Update:

Last year there was an interesting talk by Chris Bane that explains in good detail how this works:

https://www.youtube.com/watch?v=_mGDMVRO3iE

android:windowSoftInputMode=adjustResize is not working as it should be

Remove your outer Linear Layout and place everything inside a Relative Layout. And align your bottom edit text to bottom of the layout by making alignParentBottom true.
And main thing "Dont do anything to the android:windowSoftInputMode." Delete that line from manifest file.
Let android take default.

android:windowSoftInputMode=adjustResize doesn't make any difference?

I created a new project in order to try and get the basic features working for window resizing and the slowly moved it towards the target peice of my project. Doing this I tracked the problem down to this:

In my theme hierarchy I had this property:

<item name="android:windowFullscreen">true</item> 

which was burried at the level of Theme.Black.NoTitleBar.FullScreen - An ancestor of my custom theme.

The documentation suggests that this is a "Flag indicating whether this window should fill the entire screen". That sounds like a good thing to have if you have an app which takes up the whole screen... Except it still takes up the whole screen without the flag.

In fact, once you've taken this out, there is absolutely no change in the app at all... apart from adjustResize now works perfectly.

How to force windowSoftInputMode adjustResize when statusBar is hidden


public class AndroidBug5497Workaround extends AppCompatActivity {

// For more information, see https://issuetracker.google.com/issues/36911528
// To use this class, simply invoke assistActivity() on an Activity that already has its content view set.

private ViewGroup contentContainer;
private ViewTreeObserver viewTreeObserver;
private Rect contentAreaOfWindowBounds = new Rect();
private LinearLayout.LayoutParams rootViewLayout; //-->change to the view root control type of your view.
private int usableHeightPrevious = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
contentContainer = findViewById(android.R.id.content);
rootViewLayout = (LinearLayout.LayoutParams) contentContainer.getLayoutParams();
}

@Override
protected void onPause() {
super.onPause();
if (viewTreeObserver.isAlive()) {

viewTreeObserver.removeOnGlobalLayoutListener(listener);
}
}

@Override
protected void onResume() {
super.onResume();
if (viewTreeObserver == null || !viewTreeObserver.isAlive()) {
viewTreeObserver = contentContainer.getViewTreeObserver();
}

viewTreeObserver.addOnGlobalLayoutListener(listener);
}

@Override
protected void onDestroy() {
super.onDestroy();
contentContainer = null;
viewTreeObserver = null;
}

ViewTreeObserver.OnGlobalLayoutListener listener = new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
contentContainer.getWindowVisibleDisplayFrame(contentAreaOfWindowBounds);
int usableHeightNow = contentAreaOfWindowBounds.height();

if (usableHeightNow != usableHeightPrevious) {
rootViewLayout.height = usableHeightNow;
contentContainer.layout(contentAreaOfWindowBounds.left, contentAreaOfWindowBounds.top, contentAreaOfWindowBounds.right, contentAreaOfWindowBounds.bottom);
contentContainer.requestLayout();

usableHeightPrevious = usableHeightNow;
}
}
};

}

Got it from facebook/react-native issue on github. Slight simplified for a common activity. Works good with portrait and landscape, from api 21, but it not much more tested than that. Use with care.

Android Completely transparent Status Bar?

All you need to do is set these properties in your theme:

<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>

Your activity / container layout you wish to have a transparent status bar needs this property set:

android:fitsSystemWindows="true"

It is generally not possible to perform this for sure on pre-kitkat, looks like you can do it but some strange code makes it so.

EDIT: I would recommend this lib: https://github.com/jgilfelt/SystemBarTint for lots of pre-lollipop status bar color control.

Well after much deliberation I've learned that the answer to totally disabling the translucency or any color placed on the status bar and navigation bar for lollipop is to set this flag on the window:

// In Activity's onCreate() for instance
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}

No other theme-ing is necessary, it produces something like this:

Sample Image



Related Topics



Leave a reply



Submit