Show an EditText when clicking the FloatingActionButton

0

See if you can help me I'm starting to work with FloatingButton I would like when the user clicks the button an EditText appears for typing and a button at the end to delete the text, as shown below:

IcreatedthisFrameLayout

<?xmlversion="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="9dp"
    android:visibility="gone"
    android:padding="5dp">

    <EditText
        android:id="@+id/calc_txt_Prise"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal"
        android:layout_marginTop="20dp"
        android:textSize="25dp"
        android:textColor="@color/barDarkColor"
        android:textStyle="bold"
        android:hint="@string/app_name"
        android:singleLine="true" />

    <Button
        android:id="@+id/calc_clear_txt_Prise"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="10dp"
        android:layout_gravity="right|center_vertical"
        android:background="@drawable/com_facebook_close" />

</FrameLayout>

But now how could I call to display?

    
asked by anonymous 25.01.2018 / 16:49

2 answers

0
 FrameLayout frameLayout = findViewbyId(frame_layout);

 FloatingActionButton fab = findViewById(R.id.fab)
 fab.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View view){
                 frameLayout.setVisibility(View.VISIBLE);
            }
        }
    });

This should work, but I think you'd better use% horizontal because it has two direct children, and LinearLayout (if I'm not mistaken) is used when there is only one

    
25.01.2018 / 19:10
0

You could do it in two ways:

  • Inflate this FrameLayout / Inflate and use in the view of an AlertDialog

  • Put the edt and button in the same layout as the floatingbutton and work with visibility

    setVisibility (View.VISIBLE)
    setVisibility (View.GONE)

25.01.2018 / 19:11