2011-12-18 23 views
11

से setTextAppearance के बीच अंतर जब मैं setTextAppearance(this, android.R.style.TextAppearance_Medium) प्रोग्रामेटिक रूप से कॉल करता हूं तो मुझे हल्के भूरे रंग के टेक्स्ट के साथ मध्यम आकार का फ़ॉन्ट मिलता है।कोड बनाम संसाधन

हालांकि, जब मैं xml में android:textAppearance="@android:style/TextAppearance.Medium" का उपयोग करता हूं तो मुझे एक ही आकार का टेक्स्ट मिलता है लेकिन यह रंग काला होता है।

इनके बीच क्या अंतर है?

xml फ़ाइल की प्रासंगिकता का निम्नलिखित के रूप में दिखता है:

<Button 
    android:id="@+id/button1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:textAppearance="@android:style/TextAppearance.Medium" 
    android:text="Button" /> 

कोड इस तरह दिखता है:

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    Button button = (Button)findViewById(R.id.button1); 
    button.setText("This is a long text"); 
    //button.setTextAppearance(this, android.R.style.TextAppearance_Medium); 
} 

उत्तर

1

यह अलग नहीं होना चाहिए। ब्लैक के साथ textcolor:

1) अपने setTextAppearance

या

2) आपके एक्सएमएल फ़ाइलें एक एंड्रॉयड शामिल होने के बाद प्रोग्राम के पाठ का रंग बदलने के लिए: एक अलग रंग प्राप्त करने के लिए एक ही रास्ता या तो किया जा सके।

यदि आपके एक्सएमएल कोड में एंड्रॉइड है: टेक्स्टकॉलर विशेषता, एंड्रॉइड एक्सएमएल में परिभाषित एक के बजाय उस का उपयोग करेगा। यदि आप मैन्युअल रूप सेTextAppearance सेट करते हैं, तो शैली का रंग उपयोग किया जाएगा।

इसलिए, आप शायद एंड्रॉयड है: textcolor = "# 000000" उस तत्व के लिए एक्सएमएल में

+0

नहीं है, पाठ रंग कहीं भी – user204884

+0

और यह भी कोई एंड्रॉयड में परिवर्तन नहीं करते : xml में textColor = ""? – Entreco

+0

नहीं - कोड – user204884

8

सही जवाब setTextAppearance(context, android.R.style.TextAppearance_Large);

संबंधित मुद्दे