单击FloatingActionButton时,如何显示TextInputLayout EditText

时间:2018-01-25 18:42:16

标签: android android-layout android-studio

我浪费时间试图让它发挥作用而我无法做到!

我在Android Studio中用“导航抽屉”

从零开始创建了一个项目

当用户点击FloatingActionButton时,我需要在下方显示一个文本框,当我再次点击FloatingActionButton将文字发送到我的服务时。

这里是图片 enter image description here

我的app_bar_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
    tools:context="br.com.brazmob.walltoo.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email"/>

    <android.support.design.widget.TextInputLayout
        android:id="@+id/textinput"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/fab"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Input"
            android:text="TEXTTTTTTTTTT"
            android:id="@+id/busca"
            />
    </android.support.design.widget.TextInputLayout>
</android.support.design.widget.CoordinatorLayout>

爪哇

  FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        //TextDrawable trxtDrawable = new TextDrawable("AB");
        //fab.setImageDrawable(trxtDrawable);

        textinput = (TextInputLayout) findViewById(R.id.textinput);
        busca = (EditText) findViewById(R.id.busca);

        textinput.setVisibility(View.GONE);
        busca.setVisibility(View.GONE);

        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //frameLayout.setVisibility(View.VISIBLE);
                textinput.setVisibility(View.VISIBLE);
                busca.setVisibility(View.VISIBLE);
            }
        });

1 个答案:

答案 0 :(得分:0)

为您的edittext TextInputLayout

设置 ID
   fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                fab.setVisibility(View.Gone);
                textinput.setVisibility(View.VISIBLE);
                busca.setVisibility(View.VISIBLE);
            }
        });