Show Edittext by clicking the Floatingactionbutton

Asked

Viewed 130 times

0

See if you can help me I’m starting to work with Floatingbutton like when the user click on the button appears an Edittext for typing and a button at the end to delete the text as picture below:

inserir a descrição da imagem aqui

I created this FrameLayout

<?xml version="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?

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);
            }
        }
    });

That way it should work, only I think you better wear one LinearLayout horizontal because it has two direct children, and the FrameLayout(if I’m not mistaken) is used when you only have one

0

You could do it two ways:

  • Inflate this Framelayout/Inflate and use in a Alertdialog view

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.