2017-06-20 58 views
1

在我的應用程序註冊頁面中,在此處編輯文本。在這個edittext中,我想顯示浮動文本。但我試試這個下面的代碼而不是working.Anybody請告訴有關..如何在EditText中設置浮動文本?

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
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="com.citrin.popeye.dev.popeye.Registration"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/signupttl" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_marginTop="25dp" 
     android:text="Register" 
     android:textSize="24dp" 
     android:layout_weight="1" 
     android:textColor="#000000"/> 
    <TextView 
     android:id="@+id/signupttl1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_marginTop="6dp" 
     android:text="Sign up to create an account." 
     android:textSize="15dp" 
     android:layout_weight="1"/> 

    <android.support.design.widget.TextInputLayout 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:textColorHint="#BDBDBD" 
     android:layout_weight="1"> 
     <EditText 
      android:id="@+id/name" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_marginTop="38dp" 
      android:drawablePadding="20dp" 
      android:textSize="16dp" 
      android:drawableLeft="@drawable/ic_name" 
      android:inputType="textCapSentences" 
      android:hint="Name" 
      android:nextFocusDown="@+id/email"/> 
    </android.support.design.widget.TextInputLayout> 

    <android.support.design.widget.TextInputLayout 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:textColorHint="#BDBDBD" 
     android:layout_weight="1"> 
     <EditText 
      android:id="@+id/email" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_marginTop="16dp" 
      android:drawableLeft="@drawable/ic_email" 
      android:drawablePadding="20dp" 
      android:hint="Email ID" 
      android:inputType="textEmailAddress" 
      android:nextFocusDown="@+id/nation" 
      android:textSize="16dp" /> 
    </android.support.design.widget.TextInputLayout> 

    <android.support.design.widget.TextInputLayout 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:textColorHint="#BDBDBD" 
     android:layout_weight="1"> 
     <EditText 
      android:id="@+id/nation" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:drawableLeft="@drawable/ic_flag" 
      android:layout_marginTop="16dp" 
      android:drawablePadding="20dp" 
      android:textSize="16dp" 
      android:inputType="textCapWords" 
      android:hint="Nationality" 
      android:nextFocusDown="@+id/cor"/> 
    </android.support.design.widget.TextInputLayout> 

    <android.support.design.widget.TextInputLayout 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:textColorHint="#BDBDBD" 
     android:layout_weight="1"> 
     <EditText 
      android:id="@+id/cor" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:drawableLeft="@drawable/ic_country" 
      android:layout_marginTop="16dp" 
      android:inputType="textCapWords" 
      android:textSize="16dp" 
      android:drawablePadding="20dp" 
      android:hint="Country of Residence" 
      android:nextFocusDown="@+id/pass"/> 
    </android.support.design.widget.TextInputLayout> 

    <android.support.design.widget.TextInputLayout 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:textColorHint="#BDBDBD" 
     android:layout_weight="1"> 
     <EditText 
      android:id="@+id/pass" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:drawablePadding="20dp" 
      android:layout_gravity="center" 
      android:drawableLeft="@drawable/ic_pass" 
      android:layout_marginTop="16dp" 
      android:inputType="numberPassword" 
      android:textSize="16dp" 
      android:maxLength="4" 
      android:hint="Digital Secure Key password" 
      android:nextFocusDown="@+id/signup"/> 
    </android.support.design.widget.TextInputLayout> 

    <Button 
     android:id="@+id/signup" 
     android:layout_width="200dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_marginTop="40dp" 
     android:text="SIGN UP" 
     android:layout_weight="1" 
     android:textColor="#FFFFFF" 
     android:background="@drawable/btn" 
     android:layout_marginBottom="15dp" 
     android:onClick="onSignUpClick"/> 

</LinearLayout> 

</ScrollView> 

在下面,我附截圖

This is above code screenshot in android studio preview

+1

你添加的gradle設計對於依賴相同? –

+0

我使用這個android.support.design.widget.TextInputLayout。你的目標是什麼?你得到哪個錯誤? –

+0

https://guides.codepath.com/android/Working-with-the-EditText#displaying-floating-label-feedback –

回答

0
compile "com.android.support:design:$supportLibraryVersion" 

在你的build.gradle文件

+0

什麼是最新版本的支持庫? – spodee

+0

請查看此鏈接以獲取最新的庫更新[android支持庫](https://developer.android.com/topic/libraries/support-library/revisions.html) – jaffar

0

我想你已經錯過了gradle這個文件的依賴性,請檢查設計依賴性。它在我的情況下工作。

compile 'com.android.support:design:xx.x.x' 
0

添加在您的build.gradle這種依賴關係(模塊:APP)

編譯「com.android.support:design:25.2。 0'

變化25.2.0有了您的支持庫版本

我希望這會幫助你!

0

我想你應該添加這兩個依賴

compile 'com.android.support:appcompat-v7:25.3.1' 
compile 'com.android.support:design:25.3.1' 
相關問題