本文介绍了单击 FloatingActionButton 时如何显示 TextInputLayout EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我浪费了几个小时试图让它发挥作用,但我做不到!

I've wasted hours trying to make it work and I can not do it!

我在 Android Studio 中使用导航抽屉"从头开始创建了一个项目

I created a project from scratch in Android Studio with "Navigation drawer"

当用户点击 FloatingActionButton 时,我需要显示一个如下图所示的文本框,当我再次点击 FloatingActionButton 将文本发送到我的服务.

When the user clicks on the FloatingActionButton, I need to show a text box as this image below and when I click on the FloatingActionButton again to send the text to my service.

这里是图片

我的 app_bar_main.xml

My 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>

Java

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

推荐答案

Set id for your edittextTextInputLayout

Set id for your edittextTextInputLayout

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

这篇关于单击 FloatingActionButton 时如何显示 TextInputLayout EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-11 03:52