2011-06-06 14 views
12

मुझे this post जैसी ही समस्या है। मैं अपनी कस्टम अधिसूचना पाठ शैली को डिफ़ॉल्ट अधिसूचनाओं से मेल खाना चाहता हूं (मैं बस कुछ अतिरिक्त विचार जोड़ने जा रहा हूं)। दुर्भाग्य से मैं स्वीकार किए गए उत्तर को पूरी तरह से समझ नहीं पा रहा हूं। मुझे लगता है मैं XML कोड का तरीका नहीं जानते कि वास्तव में क्या जोड़ने के लिए है, लेकिन मतलब कर रहा हूँ ... enter image description hereडिफ़ॉल्ट अधिसूचना शैली का उपयोग कैसे करें?

स्वीकार किए जाते हैं जवाब कहते हैं, " समाधान में निर्मित शैलियों का उपयोग करने के लिए है। शैली आप की जरूरत TextAppearance.StatusBar है। EventContent। बस इस शैली को लागू करें और यह अधिसूचनाओं के लिए डिफ़ॉल्ट टेक्स्ट रंग सेट करेगा (एंड्रॉइड को न भूलें: निश्चित रूप से उपसर्ग)। "

मैं इसे काम करने के लिए नहीं मिल सकता! रेखा के नीचे अपने कस्टम अधिसूचना में? "एंड्रॉयड: textAppearance =" एंड्रॉयड: attr/textAppearanceLarge "काम करता है (के रूप में यह पाठ enlargens), लेकिन वांछित प्रभाव नहीं दे करता है

यहाँ मेरी कस्टम XML कोड है ...

<ImageView 
    android:id="@+id/notImage" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginRight="10dp" 
    android:layout_alignParentTop="true"/> 

<TextView 
    android:id="@+id/notContentTitle" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf ="@id/notImage" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

<TextView 
    android:id="@+id/notContentText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below ="@id/notContentTitle" 
/> 

Custom notification layouts and text colors

उत्तर

24

अंत में पता लगा मैं गलत क्या कर रहा था ... (मूल रूप से मैं एपीआई 9 से सुविधाओं का उपयोग कर रहा था जब मैं केवल एपीआई 8 पर विकास कर रहा हूं)।

सबसे पहले, एक डिफ़ॉल्ट (मंच) शैली उपयोग का उपयोग करने के ...

शैली = "@Android: शैली/TextAppearance.Small"

उदाहरण के लिए ...

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" android:padding="3dp"> 

<ImageView 
    android:id="@+id/notImage" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginRight="10dp" 
    android:layout_alignParentTop="true"/> 

<TextView 
    android:id="@+id/notContentTitle" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf ="@id/notImage" 
    android:textStyle="bold" 
    style = "@android:style/TextAppearance.Medium"/> 

<TextView 
    android:id="@+id/notContentText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below ="@id/notImage" 
    style = "@android:style/TextAppearance.Small" /> 

दूसरे StatusBar डिफ़ॉल्ट शैली उपयोग का उपयोग करने के ..

शैली = "@Android: शैली/TextAppearance.StatusBar.EventContent" या

शैली = "@Android: शैली/TextAppearance.StatusBar.EventContent.Title",

आदि, आदि

उदाहरण के लिए,

<TextView 
    android:id="@+id/notContentText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below ="@id/notImage" 
    style = "@android:style/TextAppearance.StatusBar.EventContent" /> 

मेरे मामले में इस वजह से मैं अब भी साथ एंड्रॉयड 2.2 (एपीआई 8) के विकास कर रहा हूँ, जबकि इन StatusBar शैलियों के बाद एपीआई 9 के लिए कर रहे हैं एक त्रुटि का कारण बना।(मुझे पता है मुझे अद्यतन करना चाहिए :))

उपयोगी लिंक हैं;

Android.com Applying Styles and Themes, Using Platform Styles and Themes

Android.com R.style reference

StackOverflow.com Custom notification layouts and text colours

Android.com Android API levels

+0

बस हमें यह जानकारी कर रहे हैं स्पष्ट ... वहाँ API9 करने से पहले डिफ़ॉल्ट सूचना शैलियों का उपयोग करने के लिए कोई रास्ता नहीं है, सही है? –

+0

दुर्भाग्य से, हाँ। जैसा कि मैंने अपने उत्तर में बताया है (http://stackoverflow.com/questions/4867338/custom-notification-layouts-and-text-colors/4935191#4935191), एपीआई स्तर 8 में और पहले केवल एक हार्ड-कोडित मूल्य है , जिसे एक्सेस नहीं किया जा सकता है। – Malcolm

+1

उत्तर (http://stackoverflow.com/a/7320604/435605) 2.2- के लिए रंग खोजने का एक तरीका प्रदान करता है –

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