2015-06-29 30 views
6

Xin chào, tôi đang sử dụng TextInputLayout trong ứng dụng của mình. Tôi muốn đặt màu văn bản gợi ý và màu nhãn nổi (cả tập trung và không tập trung) thành màu trắng. Tôi đã thử mã dưới đây.cách thay đổi màu văn bản gợi ý của textinputlayout

<android.support.design.widget.TextInputLayout 
android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/TextLabel"> 

<android.support.v7.widget.AppCompatEditText 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:hint="Hiiiii" 
android:id="@+id/edit_id"> 
</android.support.v7.widget.AppCompatEditText> 
</android.support.design.widget.TextInputLayout> 

<style name="TextLabel" parent="TextAppearance.AppCompat"> 
//hint color And Label Color in False State 
<item name="android:textColorHint">@color/Color Name</item> 
<item name="android:textSize">20sp</item> 
//Label color in True State And Bar Color False And True State 
<item name="colorAccent">@color/Color Name</item> 
<item name="colorControlNormal">@color/Color Name</item> 
<item name="colorControlActivated">@color/Color Name</item> 
</style> 

Nó hoạt động bình thường cho kẹo nhưng không phải cho các phiên bản thấp hơn. Tôi có thể đạt được điều tương tự trong các phiên bản thấp hơn không?

Trả lời

0

Tôi đã nhận được câu trả lời cho điều này. Trong các phiên bản hệ điều hành thấp hơn so với kẹo que, chúng tôi phải đặt màu văn bản là màu trắng (trong trường hợp của tôi) trong chủ đề ứng dụng. Sau đó, nó sẽ làm việc.

0

Give cùng phong cách-Text Input Style rằng bạn đang đưa ra để Edittext

<!--Text Input Style--> 
    <style name="styleTextInputLayout" parent="Widget.Design.TextInputLayout"> 
     <item name="android:textColor">?android:attr/textColorSecondary</item> 
     <item name="android:textColorHint">?android:attr/textColorSecondaryInverse</item> 
    </style> 


<!--EditText--> 
    <style name="styleEditText" parent="Widget.AppCompat.EditText"> 
     <item name="android:textColor">?android:attr/textColorSecondary</item> 
     <item name="android:textColorHint">?android:attr/textColorSecondaryInverse</item> 
    </style> 

cho màu sắc tương ứng của bạn để thẻ ở trên

<android.support.design.widget.TextInputLayout 
        style="@style/styleTextInputLayout" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"> 

        <EditText 
         android:id="@+id/edtTextFirstName" 
         style="@style/styleEditText" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_marginBottom="@dimen/dimen_5_dp" 
         android:layout_marginTop="@dimen/dimen_5_dp" 
         android:hint="@string/hint_first_name" 
         android:imeOptions="actionNext" 
         android:inputType="textPersonName|textCapWords" 
         android:singleLine="true" /> 
       </android.support.design.widget.TextInputLayout> 

mã ở trên làm việc với

compile 'com.android.support:appcompat-v7:23.0.1' 
compile 'com.android.support:design:23.0.1' 

Tôi đang đối mặt vấn đề với phiên bản 22, có thể có một số lỗi do Kiểu nhập văn bản bỏ qua kiểu được cung cấp cho nó.

Giải pháp cho com.android.support:design dưới 23 là:

style.xml

<style name="styleTextInputTextAppearance" parent="TextAppearance.AppCompat"> 
     <item name="android:textColorHint">?android:attr/textColorSecondaryInverse</item> 
    </style> 

bộ theme để TextInputLayout

<android.support.design.widget.TextInputLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:theme="@style/styleTextInputTextAppearance"> 

        <EditText 
         android:id="@+id/edtTextTowerName" 
         style="@style/styleEditText" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_marginBottom="@dimen/dimen_5_dp" 
         android:layout_marginTop="@dimen/dimen_5_dp" 
         android:hint="@string/hint_tower_name" 
         android:imeOptions="actionNext" 
         android:inputType="textCapWords" 
         android:singleLine="true" /> 
       </android.support.design.widget.TextInputLayout> 
Các vấn đề liên quan