2010-12-16 7 views
6

मैंने कुछ स्टाइल संसाधनों को परिभाषित किया है जिनमें एक परिभाषित टेक्स्टकॉलर के साथ टेक्स्टएपियरेंस शामिल है। मैं फिर कुछ टेक्स्ट व्यू और बटन पर शैलियों को लागू करता हूं। सभी शैलियों टेक्स्टव्यू के साथ आती हैं, लेकिन बटन नहीं। किसी कारण से, टेक्स्ट रंग विशेषता प्रदर्शित नहीं हो रही है। क्या यह एक बग है, या क्या मुझे बटन के मामले में कुछ याद आ रहा है?टेक्स्टकॉलर को टेक्स्ट व्यू पर लागू किया जा रहा है, लेकिन बटन नहीं?

यहाँ शैली परिभाषा है:

<?xml version="1.0" encoding="UTF-8"?> 
<resources> 

    <style name="TestApp">  
    </style> 

    <!-- Text Appearances --> 
    <style name="TestApp.TextAppearance"> 
     <item name="android:typeface">sans</item> 
     <item name="android:textStyle">bold</item> 
     <item name="android:textSize">16px</item>  
     <item name="android:textColor">#6666FF</item> 
    </style> 

    <!-- Widget Styles --> 
    <style name="TestApp.Widget"> 
     <item name="android:layout_margin">3sp</item> 
    </style> 

    <style name="TestApp.Widget.Label"> 
     <item name="android:textAppearance">@style/TestApp.TextAppearance</item> 
     <item name="android:layout_width">wrap_content</item> 
     <item name="android:layout_height">wrap_content</item> 
    </style> 

    <style name="TestApp.Widget.Switch"> 
     <item name="android:textAppearance">@style/TestApp.TextAppearance</item> 
     <item name="android:layout_width">100px</item> 
     <item name="android:layout_height">100px</item> 
    </style> 

</resources> 

और यहाँ लेआउट जहाँ मैं उन्हें लागू करने का प्रयास है:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
<TextView 
    style="@style/TestApp.Widget.Label" 
    android:text="This is my label." /> 
<TextView 
    style="@style/TestApp.Widget.Label" 
    android:text="This is my disabled label." 
    android:enabled="false" /> 
<Button 
    style="@style/TestApp.Widget.Switch" 
    android:text="This is my switch." /> 
<Button 
    style="@style/TestApp.Widget.Switch" 
    android:text="This is my disabled switch." 
    android:enabled="false" /> 
</LinearLayout> 

उत्तर

2

स्पष्ट रूप से यह प्राप्त करने का तरीका बटन स्टाइल में textColor विशेषता को ओवरराइड करना है। एंड्रॉइड इसे अपने वैश्विक थीम शैलियों में इस तरह से करता है:
https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/styles.xml

मुझे यह समझना अच्छा लगेगा कि ऐसा क्यों है।

+1

मुझे सही समस्या थी और मैंने टेक्स्ट को ओवरराइड करने का हल किया। ऐसा लगता है कि बटन टेक्स्ट एप्योरेंस विशेषता को अनदेखा करते हैं। –

0

वहाँ के रूप में अच्छी तरह से एक textAppearanceButton प्रतीत होता है:

http://developer.android.com/reference/android/R.attr.html#textAppearanceButton

आप इसे आजमा सकते हैं।

+1

मैं के बारे में पता नहीं था वह विशेषता। हालांकि, इसका कोई प्रभाव नहीं पड़ा। किसी कारण से ऐसा प्रतीत होता है कि एक शैली के माध्यम से प्रदान किए जाने पर टेक्स्टकॉलर विशेषता को बटन और व्युत्पन्न कक्षाओं द्वारा अनदेखा किया जाता है। शैली के बिना सेट होने पर यह केवल प्रभावित होता है। – jsmith

1

बटन के मामले में, गुणों के माध्यम से टेक्स्ट रंग को परिभाषित करने के दो तरीके हैं: textColor और textAppearance द्वारा परिभाषित शैली के माध्यम से।

textColor (जिसे डिफ़ॉल्ट शैली द्वारा सेट किया गया है) द्वारा निर्धारित मान textAppearance शैली द्वारा सेट किए गए किसी भी टेक्स्ट रंग मान को ओवरराइड करेगा। इसलिए आपको textColor विशेषता को दो तरीकों से @null पर सेट करना होगा।

<style name="Application.Button"> 
    <item name="android:textAppearance">@style/Application.Text.Medium.White</item> 
    <item name="android:textColor">@null</item> 
</style> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    style="@style/Application.Button" /> 
  • सेट textcolor बटन XML में @null लिए:

    • textcolor शैली में @null करने के लिए सेट

      <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      style="@style/Application.Button" 
      android:textColor="@null" /> 
      
  • संबंधित मुद्दे