Search code examples
androidandroid-edittextkeypad

Add two Buttons to the Soft Keyboard


I am able to add a done button to soft keyboard but I also want to add a Del Button is this possible if yes please tell me how ?

enter image description here


Solution

  • Create an sample.xml layout file

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:layout_alignParentBottom="true"
            android:gravity="bottom"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <EditText
                android:gravity="left"
                android:background="#e4e4e4"
                android:layout_width="0dp"
                android:layout_weight="8"
                android:layout_height="match_parent" />
            <LinearLayout
                android:orientation="vertical"
                android:layout_weight="2"
                android:layout_width="0dp"
                android:layout_height="wrap_content">
                <Button
                    android:text="Done"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
                <Button
                    android:text="Del"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
            </LinearLayout>
        </LinearLayout>
    </RelativeLayout>
    

    Create the Sample.java Activity file

    public class Sample extends Activity {
        @Override
        protected void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.sample);
        }
    }
    

    Make sure you add android:windowSoftInputMode="adjustResize" in the manifest file like below.

    <activity android:name=".Sample"
               android:windowSoftInputMode="adjustResize">
    </activity>
    

    enter image description here