android输入法弹出时,整个页面上移(使输入法位于页面底部),怎么实现?
怪我咯
怪我咯 2017-04-17 14:25:52
0
3
877

windowSoftInputMethod我是知道的,也都试了下,没有解决,windowSoftInputMethod的结果好像是跟页面具体的布局有挺大关系的,我想解决的大概是这么2个问题,1.能不能使得输入法显示在任意你想要的位置,2.如果1无法实现,能不能使得输入法显示在整个页面的底部(整个页面上移)。

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(3)
迷茫

My idea: Use ScrollView to wrap the main content in the middle, and then remove the scroll bar of ScrollView.
The effect and layout code are as follows:
Note: I am currently testing that the layout below still cannot be moved up on only Android 4.4 machines. I don’t know the reason and hope to discuss it together.

Updated answer : 4.4 bug resolution, it seems that I am committing suicide in order to adapt to the status bar color of 4.4, I specially added a line in stylev19: <item name ="android:windowTranslucentStatus">true</item>

It is this line of code that causes it to be invalid on 4.4. The reason is currently unknown.
As a reminder, it is best to add

in the manifest file
android:windowSoftInputMode="adjustResize"

In order for the "Next" button below to always be displayed at the bottom, I made a nest with a linearlayout of android:layout_weight=1.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom"
    android:orientation="vertical"
    tools:context="com.luckingus.sns.ui.account.InviteActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <ScrollView
            android:id="@+id/scrollView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fadeScrollbars="false">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="226dp"
                    android:background="@color/colorPrimary">

                    <TextView
                        android:id="@+id/textView2"
                        android:layout_width="match_parent"
                        android:layout_height="68dp"
                        android:layout_alignParentBottom="true"
                        android:background="@color/colorPrimaryDark"
                        android:gravity="center_vertical"
                        android:paddingLeft="32dp"
                        android:text="验证邀请码"
                        android:textColor="@color/md_white"
                        android:textSize="@dimen/textSize_24sp" />

                    <ImageView
                        android:layout_width="65dp"
                        android:layout_height="64dp"
                        android:layout_alignBottom="@+id/textView2"
                        android:layout_alignParentEnd="true"
                        android:layout_alignParentRight="true"
                        android:layout_marginBottom="52dp"
                        android:layout_marginEnd="36dp"
                        android:layout_marginRight="36dp"
                        android:src="@drawable/logo" />

                </RelativeLayout>


                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:foreground="@drawable/bottom_shadow">

                    <android.support.design.widget.TextInputLayout
                        android:id="@+id/til_invite"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/text_input_layout_heigh"
                        android:layout_marginLeft="32dp"
                        android:layout_marginRight="32dp"
                        android:layout_marginTop="@dimen/dp20">

                        <EditText
                            android:id="@+id/et_invite"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:ems="10"
                            android:hint="@string/input_invite" />
                    </android.support.design.widget.TextInputLayout>

                </FrameLayout>

            </LinearLayout>
        </ScrollView>
    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/background_dock"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/tv_next"
            style="@style/TextButtonRegister"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:drawableRight="@drawable/ic_chevron_right_grey600_24dp"
            android:text="@string/next_step" />

        <TextView
            android:id="@+id/tv_last"
            style="@style/TextButtonRegister"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:drawableLeft="@drawable/ic_chevron_left_grey600_24dp" />
    </RelativeLayout>
</LinearLayout>
刘奇

Method 1: Write this code getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) before setContentView in oncreate in your activity;
Method 2: Correspond to the interface in the AndroidManifest.xml file of the project Add android:windowSoftInputMode="stateVisible|adjustResize" to <activity>, which will move the entire screen upward. If you add android:windowSoftInputMode="adjustPan", the keyboard will cover the screen.
Method 3: Replace the top-level layout with ScrollView, or add a layer of ScrollView encapsulation on top of the top-level Layout. This will scroll the soft keyboard and the input box together, and the soft keyboard will always be at the bottom.

刘奇

Let’s see if it can be achieved using iscroll

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template