【发布时间】: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 -
并且建议使用
TextInputEditText和TextInputLayout而不是普通的EditTextdeveloper.android.com/reference/android/support/design/widget/… -
@MohammedAtif 刚试过
android.support.design.widget.TextInputEditText。当我使用它时,它变得完全不可见且不可点击 -
你能添加
colors.xml文件吗? -
@IulianPopescu 添加了
标签: android xml material-design