2017-02-23 35 views
0

我正在創建測驗並嘗試爲答案創建一致的樣式。我試圖改變CheckBoxes的字體顏色,但它沒有改變。雖然大小確實改變。Android Studio中的自定義樣式不起作用

這就是我對CheckBox規範的樣式和示例。當我在視圖中輸入android:textColor =「#eeba30」時,文本顏色會更改爲正確的顏色。

<style name="AnswerTextStyle"> 
    <item name="android:layout_width">match_parent</item> 
    <item name="android:layout_height">wrap_content</item> 
    <item name="android:textSize">50sp</item> 
    <item name="android:textColor">#eeba30</item> 
</style> 

<CheckBox 
    android:id="@+id/q1_correct1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:onClick="question1" 
    android:text="Ireland" 
    android:textAppearance="@style/AnswerTextStyle"/> 

回答

0

試試這個,

<CheckBox 
     android:id="@+id/checkbox" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:button="@drawable/selector_checkbox" 
     android:paddingStart="10dp" 
     android:onClick="question1" 
     android:text="Ireland" /> 

style.xml

  <!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
     <item name="android:checkboxStyle">@style/customCheckBoxStyle</item> 
    </style> 


    <style name="customCheckBoxStyle" parent="@android:style/Widget.CompoundButton.CheckBox"> 
    <item name="android:textColor">#eeba30</item> 
    <item name="android:textSize">50sp</item> 
    </style> 

selector_checkbox

<?xml version="1.0" encoding="utf-8"?> 
    <selector xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item android:state_checked="true" android:drawable="@drawable/ic_selected" /> 
    <item android:drawable="@drawable/ic_unselected" /> 
    </selector> 

OR

<CheckBox 
    android:id="@+id/checkbox" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:button="@drawable/selector_checkbox" 
    android:paddingStart="10dp" 
    android:onClick="question1" 
    android:textSize="50sp" 
    android:textColor="#eeba30" 
    android:text="Ireland" /> 
+0

對不起,我是新來的android studio ...你在這裏添加的selector_checkbox是什麼?我是否在xml文件中添加這個?如果是這樣,它給了我很多錯誤。 –

+0

在可繪製文件夾中創建selector_checkbox xml – user2025187

+0

嘗試最後一個選項如果它不起作用,請嘗試第一個 – user2025187

相關問題