2016-11-15 70 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。有效。 –