2013-07-23 9 views
8

मैं अलर्ट संवाद की पृष्ठभूमि को बदलना चाहता हूं। मैं निम्नलिखित कोड टुकड़ा की कोशिश की है ऐसा करने के लिए:एंड्रॉइड अलर्ट संवाद शीर्षक की पृष्ठभूमि को कैसे बदलें

<style name="Theme.AlertDialog" parent="@android:style/Theme.Holo.Light.Dialog"> 
     <item name="android:background">@android:color/transparent</item> 
     <item name="android:textColor">#659F26</item> 
     <item name="android:windowTitleStyle">@style/Theme.AlertDialog.Title</item> 
    </style> 

    <style name="Theme.AlertDialog.Title" parent="@android:style/TextAppearance.DialogWindowTitle"> 
     <item name="android:background">@drawable/cab_background_top_example</item> 
    </style> 

जावा कोड: इस तरह

ContextThemeWrapper ctw = new ContextThemeWrapper(this, R.style.Theme_AlertDialog); 
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ctw); 

alertDialogBuilder.setTitle(getResources().getString(R.string.confirmation)); 
alertDialogBuilder.setMessage(getResources().getString(R.string.msg));  
alertDialogBuilder.show(); 

मेरा ऐप दिखा रहा है संवाद:

enter image description here

जबकि मैं चाहता हूँ यह देखने के लिए जैसे:

enter image description here

कृपया सुझाव दें, मैं क्या गलत कर रहा हूं।

+0

का उपयोग क्यों नीचे वोट? – mudit

+0

मैं बस अपने प्रश्न से अपनी समस्या का समाधान करता हूं इसलिए मेरी तरफ से +1 ..... – duggu

उत्तर

6

इस कोड को जब एक संवाद बनाने का प्रयोग करें:

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 

अपने स्वयं के लेआउट अपने लेआउट बनाने के रूप में कई अनुकूलित शीर्षक के साथ किया तो सेट

dialog.setContentView(R.layout.yourlayout); 

नोट: उपयोग

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); before  
dialog.setContentView(R.layout.yourlayout); 

अन्यथा यह त्रुटि देता है।

+1

डिफ़ॉल्ट संवाद के लेआउट को बदलने के साथ ऐसा करने का कोई तरीका है। मैं सिर्फ शीर्षक और जिस तरीके से आप सुझाव दे रहा हूं उसे बदलना चाहता हूं, मुझे खुद को और कुछ अन्य चीजों को लेआउट करना है। – mudit

+0

हाँ आप जितनी चाहें उतनी अनुकूलित कर सकते हैं –

+2

मेरा प्रश्न: क्या पूरे लेआउट को बदलने के बजाय शैलियों के माध्यम से इसे संभालने का कोई तरीका है? – mudit

0
ContextThemeWrapper ctw = new ContextThemeWrapper(this, R.style.Theme_AlertDialog); 

"this" के बजाय इस लाइन उपयोग में ActivityName.this

+1

यह ओपी की समस्या का समाधान नहीं है। – laalto

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