本文介绍了单击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);
}
});
推荐答案
为您的edittext TextInputLayout
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!