在软键盘上方放置一个按钮

时间:2018-05-13 11:21:03

标签: android keyboard

我有一个代码来检查Softinputkeyboard是否可见。但我不知道如何将最初位于布局底部的Button设置在键盘上方。我已将布局设置为 FULL SCREEN ,因此给出 softInputMode 在Manifest中 adjustResize 不再工作了。我知道。现在我只设置" Y"按钮的位置( id = 下一步)到键盘上方的某个值。但我希望它位于键盘上方。等待您的帮助!!感谢推进..

Java代码:

final Window mRootWindow=getActivity().getWindow();
        frag1Binding.relative.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                int screenheight=frag1Binding.relative.getRootView().getHeight();
                Rect r=new Rect();
                View view=mRootWindow.getDecorView();
                view.getWindowVisibleDisplayFrame(r);
                int keyboardheight=screenheight-r.bottom;
                if (keyboardheight>150){
                    lastheight=keyboardheight;
                    Log.e("EditText_Bottom",Integer.toString(frag1Binding.phnmbr.getBottom()));
                    linearLayoutParams=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                    orginalpositon=frag1Binding.next.getY();
                    Log.e("Original Y",Float.toString(frag1Binding.next.getY()));
                    frag1Binding.next.setY(100);

                    }
            else {
                    if (lastheight>150){
                    frag1Binding.next.setY(orginalpositon);
                }}
            }
        });

XML:

<?xml version="1.0" encoding="utf-8"?>
<layout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffffff"
        android:id="@+id/relative"
        >
        <TextView
            android:id="@+id/head"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/ph_verify_lbl_mrgn"
            android:text="verify_your_phone_number"
            android:textColor="#bb2b67"
            android:textSize="@dimen/ph_verify_head_tsxtsze"
            />
        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/head"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="4dp"
            android:text="lorem_ipsum_lorem_ipsum"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="60dp"
            android:text="+91"
            android:layout_below="@+id/textView"
            android:gravity="center|bottom"
            android:id="@+id/countrycode"
            android:textSize="@dimen/ph_verify_head_tsxtsze"
            android:textColor="#000000"
            android:layout_marginTop="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginBottom="8dp"
            />
        <EditText
            android:layout_width="312dp"
            android:layout_height="60dp"
            android:id="@+id/phnmbr"
            android:layout_toRightOf="@+id/countrycode"
            android:layout_below="@+id/textView"
            android:background="@drawable/edittext_bg"
            android:hint="Hint"
            android:inputType="number"
            android:gravity="start|center|bottom"
            android:paddingLeft="20dp"
            android:layout_marginRight="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginLeft="10dp"
            android:layout_marginStart="10dp"
            android:focusable="true"
            android:fitsSystemWindows="true"
            android:focusableInTouchMode="true"
            android:freezesText="true"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            />


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

            android:layout_below="@+id/phnmbr"
            android:layout_alignParentBottom="true"
            >

            <Button
                android:id="@+id/next"
                android:layout_width="match_parent"
                android:layout_height="65dp"

                android:layout_alignParentBottom="true"
                android:background="@drawable/button_bg"
                android:text="NEXT"
                android:textColor="#ffffff"
                android:textSize="22sp">

            </Button>
            <ImageView
                android:id="@+id/imageView"
                android:layout_width="20dp"
                android:layout_height="25dp"
                android:elevation="2dp"
                android:layout_alignParentEnd="true"
                android:layout_alignParentBottom="true"
                android:layout_marginBottom="18dp"
                android:layout_marginEnd="19dp"
                android:background="@drawable/arrow"
                android:layout_alignParentRight="true"
                android:layout_marginRight="19dp"/>
        </RelativeLayout>
    </RelativeLayout>
</layout>

0 个答案:

没有答案