簡體   English   中英

TextInputLayout將EditText顏色更改為紅色

[英]TextInputLayout changing EditText color to Red

我遇到了一個奇怪的問題,其中EditText字段在Activity的開始處將顏色更改為Red ,就像在發生SetError它們會更改一樣。 另外,這並非每次都發生,僅在某些情況下才會出現。 如何解決此錯誤? 任何幫助表示贊賞。 請參考圖片了解更多。 這是代碼

 <android.support.design.widget.TextInputLayout
                    android:id="@+id/input_name"
                    style="@style/my_style_textInput"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:padding="8dp">

                    <EditText
                        android:id="@+id/edt_name"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="Name:"
                        android:inputType="textPersonName"
                        android:singleLine="true"
                        android:textSize="@dimen/subHeading" />
                </android.support.design.widget.TextInputLayout>

這是樣式:

<style name="my_style_textInput" parent="@style/TextAppearance.AppCompat">
    //hint color And Label Color in False State
    <!--<item name="android:textColorHint">@color/item_color</item>-->
    <!--<item name="android:textColor">@color/colorPrimary</item>-->
    <item name="android:textSize">@dimen/caption</item>
    //Label color in True State And Bar Color False And True State
    <item name="colorAccent">@color/colorPrimary</item>
    <item name="colorControlNormal">@color/colorPrimary</item>
    <item name="colorControlActivated">@color/colorPrimaryAccent</item>
</style>

請注意,colorPrimary,colorAccent和item_color都不是紅色的。謝謝。 在此處檢查圖像

您可以使用此代碼來自定義顏色。

在您的布局上應用android:background =“ @ drawable / edittext_bg”

<EditText
    android:la`enter code here`yout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/login_username"
    android:hint="@string/username_hint"
/>

在drawable下並創建文件edittext_bg.xml並將此代碼放入其中。

<layer-list>
 <item>
    <shape android:shape="rectangle">
    <!-- Draw a 2dp width border around shape -->
         <stroke android:color="#ff1e0c" android:width="2dp"/>
    </shape>
 </item>
 <!-- Overlap the left, top and right border using background color  -->
  <item android:bottom="2dp">
     <shape android:shape="rectangle">
        <solid android:color="#fffbce"/>
     </shape>
   </item>

希望對您有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM