-2

I want to make a button or a view that is capable of showing up above EditTexts that when is clicked, certain action is performed upon that specific focused EditText. I don't know how it's called or if there is any 3d party library that does that.

David Lasry
  • 829
  • 3
  • 12
  • 31

1 Answers1

0

That's when RelativeLayouts play a big role here since you could position views over another with the view on top having focus, and vice-versa. So first you'd compile Android's latest support design library into your local build.gradle file to use FAB, and then do something like this for the layout file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="true"
    android:focusableInTouchMode="true"
    tools:context="com.davenotdavid.stackoverflow.MainActivity">

    <EditText
        android:id="@+id/et1"
        android:hint="HINT..."
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <EditText
        android:id="@+id/et2"
        android:hint="HINT..."
        android:layout_below="@id/et1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <EditText
        android:id="@+id/et3"
        android:hint="HINT..."
        android:layout_below="@id/et2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />

</RelativeLayout>

... and then perhaps test if the FAB has focus over a focused EditText by displaying a Toast message (as opposed to EditText's keyboard popping up) in your onCreate() as follows:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(MainActivity.this, "FAB clicked", Toast.LENGTH_SHORT).show();
        }
    });
}
DaveNOTDavid
  • 1,753
  • 5
  • 19
  • 37