2016-09-18 118 views
0

我在設置android:textColor,但文字顏色不變。這是我的片段代碼。當我想要白色時,背景顏色會改變,但文字顏色會保持黑色。Android按鈕未設置文字顏色

編輯:它在Design選項卡中正確,但不在模擬器中。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/nav_bar_top_lin"> 

    <!-- Navigation --> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/linLayFrag" 
     android:layout_gravity="center_horizontal" 
     android:background="@color/navColor"> 

     <Button 
      android:layout_width="0dp" 
      android:layout_weight=".25" 
      android:background="@color/navColor" 
      android:layout_height="wrap_content" 
      android:onClick="goHome" 
      android:textColor="@color/navTextColor" 
      android:text="Home" 
      android:id="@+id/homeButton" /> 

     <Button 
      android:layout_width="0dp" 
      android:layout_weight=".25" 
      android:background="@color/navColor" 
      android:layout_height="wrap_content" 
      android:textColor="@color/navTextColor" 
      android:onClick="goVault" 
      android:text="Vault" 
      android:id="@+id/vaultButton" /> 

     <Button 
      android:layout_width="0dp" 
      android:layout_weight=".25" 
      android:background="@color/navColor" 
      android:layout_height="wrap_content" 
      android:onClick="goShop" 
      android:textColor="@color/navTextColor" 
      android:text="Shop" 
      android:id="@+id/shopButton" /> 

     <Button 
      android:layout_width="0dp" 
      android:layout_weight=".25" 
      android:background="@color/navColor" 
      android:textColor="@color/navTextColor" 
      android:layout_height="wrap_content" 
      android:onClick="goAccount" 
      android:text="Account" 
      android:id="@+id/accInfoButton" /> 

    </LinearLayout> 

    <!-- End Navigation --> 

</LinearLayout> 

這是我的色彩資源。

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <color name="colorPrimary">#3F51B5</color> 
    <color name="colorPrimaryDark">#303F9F</color> 
    <color name="colorAccent">#FF4081</color> 
    <color name="textColor">#f5f5f9</color> 
    <color name="horLine">#000000</color> 
    <color name="navColor">#7b49c6</color> 
    <color name="completeTaskColor">#158b11</color> 
    <color name="navTextColor">#ffffff</color> 
</resources> 
+0

它工作正常。 –

+0

http://stackoverflow.com/a/4692899/4450098。這可能會幫助你 –

回答

0

它在模擬器上工作得很好。這裏的截圖 -
enter image description here

你試過在不同的模擬器上?