2012-02-15 21 views
8

मैं एक कस्टम संवाद बना रहा हूं और मैं जानना चाहता हूं कि शीर्षक पट्टी की पृष्ठभूमि को कैसे बदला जाए।एंड्रॉइड - कस्टम डायलॉग शीर्षक पृष्ठभूमि बदलें

मैं दो तरीकों की कोशिश की है:

1 - मैं 'setCustomTitle' AlertDialog.Builder विधि की कोशिश की है। मैंने लेआउट चौड़ाई और ऊंचाई 'match_parent' और पृष्ठभूमि रंग के साथ एक टेक्स्टव्यू शामिल एक साधारण लेआउट दृश्य बनाया। जब मैं ऐप चलाता हूं, तो टाइटल बार का केवल शीर्ष आधा पृष्ठभूमि रंग दिखा रहा है। निचला आधा अभी भी डिफ़ॉल्ट थीम पृष्ठभूमि रंग दिखा रहा है। क्या किसी को पता है क्यों?

2 - मैंने अपना खुद का संवाद विषय बनाया है। मैंने पेरेंट विरासत के साथ '@android: style/Theme.Holo.Light.Dialog' के साथ एक शैली बनाई है। मैंने तब अलर्टडिअलॉग में बनाया है। बिल्डर कन्स्ट्रक्टर - नया अलर्टडिअलॉग.बिल्डर (यह, आर। स्टाइल.test_dialog)। यह अच्छा लगता है लेकिन किसी भी तरह संवाद एक संवाद के भीतर लपेटा जाता है। एक वर्ग बॉक्स संवाद के आस-पास है। क्या किसी को पता है क्यों?

उत्तर

35

आप एक शैली की तरह बना सकते हैं,

<style name="cust_dialog" parent="@android:style/Theme.Dialog"> 
    <item name="android:windowTitleStyle">@style/dialog_title_style</item> 
    </style> 

<style name="dialog_title_style" parent="android:Widget.TextView"> 
    <item name="android:background">@android:color/black</item> 
    <item name="android:padding">10dp</item> 
</style> 

और आप का दृष्टांत कर सकते हैं संवाद:

Dialog dialog=new Dialog(this,R.style.cust_dialog); 
dialog.setContentView(R.layout.fragment_features_dialog); 
dialog.setTitle(R.string.features); 

अब संवाद काला शीर्षक पृष्ठभूमि रंग के साथ दिखाता है।

+0

हाय, उत्तर के लिए धन्यवाद, जैसे कस्टम शीर्षक बनाएं। अलर्ट के साथ कैसे आते हैं। बिल्डर एक अलग यूआई दिखाता है? अलर्टडिअलॉग। बिल्डर टेस्टबिल्डर; testbuilder = new AlertDialog.builder (यह, R.style.cust_dialog); \t testbuilder।setview (लेआउट); मैं मूल थीम थीम का उपयोग कर रहा हूं। Holo.Light.Dialog। जब भी मैं Alertdialog.builder का उपयोग करता हूं, तो संवाद एक संवाद के भीतर लपेटा जाता है। क्या किसी को पता है क्यों? – CLDev

4

डायलॉग-लिपटे-इन-ए-डायलॉग उपस्थिति संवाद की विंडो पृष्ठभूमि के कारण होती है। प्रत्येक संवाद में यह होता है, लेकिन डिफ़ॉल्ट एंड्रॉइड संवाद में खिड़की की पृष्ठभूमि पारदर्शी होती है। मैं मोनो एंड्रॉयड (Xamarin) का उपयोग कर रहा

<style name="CustomDialog" parent="@android:style/Theme.Holo.Dialog"> 
    <item name="android:windowBackground">@android:color/transparent</item> 
</style> 
1

; ऐसा करने के लिए, अपने कस्टम संवाद विषय में इस मद जोड़ने

Dialog itemDialog = new Dialog(this.Activity); 
TextView alertTitle=(TextView)itemDialog.Window.DecorView.FindViewById(Android.Resource.Id.Title); 

alertTitle.SetTextColor(Android.Graphics.Color.Blue); 
alertTitle.SetBackgroundColor(Android.Graphics.Color.Orange); 
itemDialog.SetContentView(Resource.Layout.listview_custom_dialog); 
string[] options = new string[] { "Open", "Mark as Unread","Mute","View  
Profile","Block Connection","Delete Conversation" }; 
ArrayAdapter<string> adapter = new ArrayAdapter<string>(this.Activity, 
Resource.Layout.listitem_custom_dialog,Resource.Id.textViewDialogDescription, 
options); 

Resource.Layout.listitem_custom_dialog: यदि आप किसी अन्य विकल्प है कि मेरे ऐप में उपयोग कर रहा हूँ एक टुकड़ा में एक संवाद बनाने के लिए दिखा रहा

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@android:color/transparent" > 
<TextView 
    android:id="@+id/textViewDialogDescription" 
    android:layout_width="match_parent" 
    android:layout_height="44dp" 
    android:background="#ffffff" 
    android:textColor="#386B96" 
    android:paddingLeft="4dp" 
    android:textSize="14dp" /> 
</RelativeLayout> 

ListView lv = itemDialog.FindViewById<ListView> 
(Resource.Id.listViewDialogItems); 
lv.Adapter = adapter; 
adapter.NotifyDataSetChanged(); 
itemDialog.SetCancelable(true); 
itemDialog.SetTitle("Conversation"); 
itemDialog.Show(); 
: इस कस्टम सूचीदृश्य लेआउट यहाँ है xml फ़ाइल है,

एंड्रॉइड.Resource.Id.Title: यह संवाद शीर्षक वाला टेक्स्टव्यू आईडी है। और यह एंड्रॉइड द्वारा पूर्वनिर्धारित है। इस तरह आपको एक संवाद मिलेगा जिस तरह से आप शैली में शैली बना सकते हैं।

+0

एंड्रॉइड स्टूडियो में 'टेक्स्ट व्यू शीर्षक दृश्य = (टेक्स्ट व्यू) myDialog.findViewById (android.R.id.title);', पूरी तरह से काम करता है। – grabarz121

1

अपनी पुस्तक के लिए XML लेआउट फ़ाइल बनाएं और उसे बढ़ा देते हैं और आप सिर्फ इस

LayoutInflater inflater = this.getLayoutInflater(); 
View titleView = inflater.inflate(R.layout.custom_title, null); 

new AlertDialog.Builder(SubCategoryActivity.this) 
        .setCustomTitle(titleView); 

की तरह और custom_title लेआउट आप कर सकते हैं में कस्टम शीर्षक सेट कर सकते हैं के रूप में

View view = getLayoutInflater().inflate(R.layout.cust_dialog_title, null); 
alertDialog.setCustomTitle(view); 
1

AlertDialog करने के लिए सेट इस

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:paddingLeft="10dp" 
     android:paddingRight="10dp" 
     android:id="@+id/llsubhead" 
     android:background="@color/colorPrimary"> 

     <TextView 
      android:id="@+id/exemptionSubHeading4" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dp" 
      android:layout_marginBottom="10dp" 
      android:layout_weight="1" 
      android:text="Exemption Sub Head" 
      android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium" 
      android:textColor="@color/white" /> 
    </LinearLayout> 
</LinearLayout> 
संबंधित मुद्दे