2016-11-15 74 views
0

獨立的提示,我想告訴用戶關於其應當低於爲TextInputLayout和AutocompleteTextView

enter image description here

所以我用AutocompleteTextView內TextInputLayout像下面的代碼

<android.support.design.widget.TextInputLayout 
    android:id="@+id/profile_youraddress" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/profile_emailaddress" 
    android:layout_marginTop="@dimen/margin_10" 
     android:hint="@string/your_address" 
    android:textColor="@color/home_primary_color"> 

    <AutoCompleteTextView 
     android:id="@+id/profile_addresstext" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:hint="Malviya Nagar, New Delhi, Delhi" 
     android:singleLine="true" /> 
</android.support.design.widget.TextInputLayout> 
喜歡的類型定位模式

問題是,當TextInputLayout不在焦點時,它有兩個提示相互重疊,如下所示 enter image description here

我該如何重寫TextInputLayout的AutocompleteTextView提示在非可聚焦狀態下的提示?任何幫助將不勝感激。

我在尋找:

焦點不,提示應該是「你的地址」(「馬爾維亞格爾,新德里,印度」應該被隱藏),當焦點提示應該是「新德里,德里的Malviya Nagar」。

+0

參考http://stackoverflow.com/questions/30537413/textinputlayout-not-showing-edittext-hint-before-user-focus-on-it – sasikumar

+0

我有已經檢查出...這不是問題在這裏....我已經在使用'compile'c​​om.android.support:design:23.4.0''。 –

+0

你在找什麼行爲?也就是說,在你的第二張圖片中,你想讓提示成爲「你的地址」還是「新德里新德里的Malviya Nagar」? –

回答

1

做它用OnFocusChangeListener:

TextInputLayout text; 
AutoCompleteTextView auto; 
View.OnFocusChangeListener listener; 

    text = (TextInputLayout) findViewById(R.id.profile_youraddress); 
      auto = (AutoCompleteTextView) findViewById(R.id.profile_addresstext); 
      auto.setFocusable(true); 

      listener = new View.OnFocusChangeListener() { 
       @Override 
       public void onFocusChange(View v, boolean hasFocus) { 
        if (!hasFocus) { 
         auto.setHint("Malviya Nagar, New Delhi, Delhi"); 
         text.setHint(""); 
        }else { 
         auto.setHint(""); 
         text.setHint("Your address"); 
        } 
       } 
      }; 

      auto.setOnFocusChangeListener(listener); 
+1

謝謝Nidhi。有效。 –