【问题标题】:TextInputLayout isn't showingTextInputLayout 没有显示
【发布时间】:2016-10-11 07:39:07
【问题描述】:

我是 Android 应用开发领域的新手。我目前正在尝试一些基本的东西。目前我正在尝试实现一个浮动标签,就像在各种材料设计应用程序中看到的那样。

我想要做的是获得一个CardView 并在该卡中放置一个TextInputLayout

<android.support.v7.widget.CardView
        android:layout_width="310dp"
        android:layout_height="250dp"
        android:layout_below="@+id/textView"
        android:layout_alignRight="@+id/textView"
        android:layout_alignEnd="@+id/textView"
        android:layout_marginTop="13dp" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <EditText
                    android:id="@+id/labeltest"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:hint="floating label"/>
            </android.support.design.widget.TextInputLayout>
        </RelativeLayout>
    </android.support.v7.widget.CardView>

现在,当我这样做时,我得到了一个我应该得到的 CardView,但 TextInputLayout 没有出现。但是,我可以点击它,然后它会聚焦并让我输入文本。 (见下面的例子)

我想补充一点,我是在虚拟机上测试它,而不是在实际设备上。

谢谢。

编辑:根据要求,colors.xml

<resources>
    <color name="colorPrimary">#E43F3F</color>
    <color name="colorPrimaryDark">#E12929</color>
    <color name="primary_darker">#CC1D1D</color>
    <color name="colorAccent">#FFFFFF</color>

    <color name="black">#000000</color>
    <color name="jet">#222222</color>
    <color name="oil">#333333</color>
    <color name="monsoon">#777777</color>
    <color name="jumbo">#888888</color>
    <color name="aluminum">#999999</color>
    <color name="base">#AAAAAA</color>
    <color name="iron">#CCCCCC</color>
    <color name="white">#FFFFFF</color>
    <color name="Trans_text">#a8ffffff</color>
</resources>

【问题讨论】:

  • android:layout_height="wrap_content" 在编辑文本中。在您当前的代码中,父母有 wrap_content 和孩子有 match_parent 相互取消为 0,所以请确保有正确的孩子和父母 layout_params
  • 并且建议使用TextInputEditTextTextInputLayout而不是普通的EditTextdeveloper.android.com/reference/android/support/design/widget/…
  • @MohammedAtif 刚试过android.support.design.widget.TextInputEditText。当我使用它时,它变得完全不可见且不可点击
  • 你能添加colors.xml文件吗?
  • @IulianPopescu 添加了

标签: android xml material-design


【解决方案1】:

如果您阅读Material Design Guidelines,您会发现colorAccent 被用作字段下方行的颜色。您将colorAccent 设置为白色(请参阅colors.xml 文件)所以,我的猜测是TextInputLayoutparent 的背景颜色混合,这也是白色或类似的东西。尝试将colorAccent 更改为红色或其他东西,看看是否是问题所在。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-10
    • 2018-07-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多