How can I position a layout right above the android on-screen keyboard?

前端 未结 3 1447
别跟我提以往
别跟我提以往 2020-12-12 23:02

See the attached photo. Twitter does it well. They have a layout, which I will call a toolbar for lack of a better term, right above the onscreen keyboard. How can I do this

相关标签:
3条回答
  • 2020-12-12 23:10

    Make sure your soft input mode is set to adjustResize, then place the layout with your toolbar at the bottom of your activity.

    Example:

    <LinearLayout android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        <FrameLayout android:id="@+id/my_content"
                android:layout_width="match_parent"
                android:layout_height="0dip"
                android:layout_weight="1">
            <!-- Your content here -->
        </FrameLayout>
        <LinearLayout android:id="@+id/my_toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            <!-- Your toolbar items here -->
        </LinearLayout>
    </LinearLayout>
    
    0 讨论(0)
  • 2020-12-12 23:17

    Important addition to the answers above.

    When you work with DialogFragment fullscreen is applied implicitly.

    That means that you have to:
    1) set style in onCreate() of your DialogFragment:

    public class YourDialogFragment extends DialogFragment {
    ...
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Holo_NoActionBar);
            }
    }
    

    2) if you use your own theme you should handle it like this:

    <style name="AppTheme" parent="AppBaseTheme">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowFullscreen">false</item>
    </style>
    
    0 讨论(0)
  • 2020-12-12 23:22

    This is for people who after setting the adjustResize still did not work, there is an article: adjustResize does not work in fullscreen

    I indeed had this set to fullscreen, when setting my theme back to a nonfullscreen theme the layouts resized just as wanted.

    0 讨论(0)
提交回复
热议问题