10

There are questions talking about this problem but I didn't solve mine by existed answers.

This is my styles-v21.xml:

<style name="MainTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
    <item name="android:colorBackground">#EEEEEE</item>
</style>

I've set windowSoftInputMethod="adjustResize" for related Activity of course.

Here is my layout.xml, notice that the root FrameLayout is used for specific function thus it is needed:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/rl_background"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!--This View is used to fill the space of status bar-->
        <View
            android:id="@+id/statusbar"
            android:layout_width="match_parent"
            android:layout_height="@dimen/statusbar_size"/>

        <!--I've set this toolbar as Actionbar-->
        <android.support.v7.widget.Toolbar
            android:id="@+id/actionbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_below="@id/statusbar"/>

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/actionbar">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <!-- Two EditTexts inside -->

            </RelativeLayout>

        </ScrollView>

    </RelativeLayout>

</FrameLayout>

When I don't touch the EditText, everything looks fine: status bar View stays where it should be and navigation bar doesn't overlay content(doen't make content invisible but content is under it in fact).

In similar questions, people often teach us to set fitsSystemWindow="true", I did this to different layouts inside my layout.xml and got different results.

Setting fitsSystemWindow="true" in:

1.FrameLayout: AdjustResize works, but status bar View now stays below the real status bar. Status bar's color turns to windowBackground. Navigation bar became entirely transparent because it shows other fragment's content where this fragment was added.

2.First RelativeLayout: AdjustResize works, but status bar View was below real status bar.Navigation bar isn't too transparent to show other fragment but overlays content.

3&4.ScrollView&RelativeLayout inside ScrollView: AdjustResize doesn't work and others are same to condition 2.

I also used a method to write my own FrameLayout like this:https://stackoverflow.com/a/22266717/3952691 but as the author said, setting bottom will cause error. Because I use translucent navigation bar, I also need to draw bottom inset. And I try its upgrade version:https://gist.github.com/romannurik/8919163, no use too.

Sorry for can't provide pictures but I really need help.Thank you!

Community
  • 1
  • 1
ywwynm
  • 11,573
  • 7
  • 37
  • 53

0 Answers0