2016-07-30 183 views
0

美好的一天,Android EditText文字顏色總是白色

我有一個真正令人發狂的問題。
出於某種原因,我的自定義主題中的EditText組件的textColor屬性未生效。

請注意,我的自定義主題的其他一切都在工作,這只是'textColor'部分給出了麻煩。

我見過同樣的問題的其他人,他們的'解決方案'不適合我。


TextView color is always white for AppCompatActivity
Edittext color is white in appcompat 22.2

[我的代碼,並設置]

的Android Studio版本 2.1.1

CustomTheme XML片段

[文章張貼在此之前引用]
<style name="CustomTheme" parent="@style/AppTheme"> 
    <item name="editTextStyle">@style/CustomEditText</item> <!-- I'm extending AppCompatActivity, hence no 'android:' prefix! --> 
</style> 

<style name="CustomEditText" parent="@android:style/Widget.EditText"> 
    <item name="android:background">@drawable/custom_edit_text</item> 
    <item name="android:textColor">#333333</item> 
    <item name="android:paddingLeft">12dp</item> 
    <item name="android:paddingRight">12dp</item> 
    <item name="android:paddingTop">8dp</item> 
    <item name="android:paddingBottom">8dp</item> 
</style> 

Android清單XML片段

<application android:theme="@style/CustomTheme">...</application> 

的build.gradle(APP)片段

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.3" 

    defaultConfig { 
    minSdkVersion 18 
    targetSdkVersion 23 
    } 
} 

dependencies { 
    compile 'com.android.support:appcompat-v7:23.1.1' <!-- I've even tried this version v7:23.4.0 --> 
} 

在此先感謝您的幫助。

+0

可以請你分享包含EditText的佈局 –

+0

@youzking謝謝你建議我發佈佈局。當我複製佈局代碼來更新我的問題時,我認識到'textColor'在佈局xml中被設置爲白色,並且導致了問題。多虧了密爾,多麼愚蠢的錯誤。 – add

+0

你非常歡迎,很高興它幫助你。 –

回答

0

根據youzking的意見徵詢活動版面的副本。我看到我在活動的佈局xml中將'textColor'設置爲白色。因此,這是問題,因爲它覆蓋了主題'textColor'。