2016-10-11 45 views
1

我是Android應用程序開發領域的新手。我目前正在嘗試一些基本的東西。目前,我正在嘗試實現像各種材質設計應用中看到的浮動標籤。TextInputLayout未顯示

我想要做的是得到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顯示不出來。不過,我可以點擊它,然後重點並讓我輸入文字。 (請參閱下面的示例)

我想補充一點,我在虛擬機上測試它,而不是在實際設備上測試它。

謝謝。

Example 1

編輯:根據要求,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> 
+0

'android:layout_height =「wrap_content」'in edit text。在你當前的代碼中,parent有wrap_content,child有match_parent,它們相互抵消爲0,因此確保有適當的子代和父代。layout_params –

+0

建議在TextInputLayout中使用'TextInputEditText'而不是普通的'EditText' https ://developer.android.com/reference/android/support/design/widget/TextInputEditText.html –

+0

@MohammedAtif剛剛嘗試過'android.support.design.widget.TextInputEditText'。當我使用它時,它變得完全不可見且不可點擊 –

回答

1

如果你讀Material Design Guidelines你會發現colorAccent作爲顏色的場線下。您將colorAccent設置爲白色(請參閱colors.xml文件),因此,我的猜測是TextInputLayoutparent的背景顏色混合,該背景顏色也是白色或類似的。嘗試改變紅色colorAccent或其他東西,看看它是否是問題。