浮动标签提示(TextInputLayout)不适用于Android数据绑定 [英] Float Label hint (TextInputLayout) not works with Android Data Binding

查看:73
本文介绍了浮动标签提示(TextInputLayout)不适用于Android数据绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在应用程序中创建字段编辑页面.有用于编辑联系人的EditText列表.对于每种字段类型,我都有一个布局.作为示例-对于名称和姓氏,它是带有浮动标记的编辑文本.对于facebook-使用图标简单编辑文本.我正在使用Android数据绑定库创建此列表

I need create fields edit page in app. There are list of EditText for edit Contact. For each field type i have an layout. As example - for name and last name it is float labeled edit text. For facebook - simple edit text with icon. I am creating this list with Android Data Binding Library

我已经创建了布局

<data>

    <variable
        name="item"
        type="app.core.db.model.Field" />
</data>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="65dp"
        app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout"
        app:theme="@style/EditFieldFloatLabeled">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:hint="@{item.getHint()}"
            android:imeOptions="actionNext"
            android:maxLines="1" />
    </android.support.design.widget.TextInputLayout>

</FrameLayout>

但是浮动标签不起作用.我开始逐行评论以找出原因.当我评论了一行后,浮动标签就开始起作用了

But float label not works. I starts commenting line by line to find out reason. Float label became work when I've commented line

android:hint="@{item.getHint()}

(并用硬编码文本替换). getHint()根据字段类型返回R.string.{something}.

(And replace it with hardcoded text). getHint() returns R.string.{something} based on field type.

我发现,以编程方式设置提示会导致浮动标签消失.我不能使用静态布局(取而代之的是回收站视图),因为字段列表会动态增加(例如:我在字段中写入电话号码,并在其他电话号码后插入空白的电话"字段).

There I've found out than programmatically setting hint produce float label disappearing. I can not use static layout (instead recycler view) because fields list can increase dynsmically (ex: I am writing phone number in field and empty Phone field inserts after it for other phone number).

是否可以通过相同的方式(通过使用字段类型定义提示)来创建浮动标签?

Is there way to create float label same way (by defining hint with field type)?

推荐答案

我遇到了同样的问题.

解决方案是在TextInputLayout上设置带有数据绑定的提示.

The solution is setting the hint with the data binding on the TextInputLayout.

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="65dp"
    android:hint="@{item.getHint()}"
    app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout"
    app:theme="@style/EditFieldFloatLabeled">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:imeOptions="actionNext"
        android:maxLines="1" />
</android.support.design.widget.TextInputLayout>

这篇关于浮动标签提示(TextInputLayout)不适用于Android数据绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆