2013-05-27 11 views
5

मैं इस अलर्टडिअलॉग हरे रंग के तीन आइटम बनाने की कोशिश कर रहा हूं। समस्या यह है कि वर्तमान में चेतावनी के पीछे एक हरा पृष्ठभूमि दिखाई देती है, और दो आइटम हरे रंग में दिखाई नहीं देते हैं। मैं वर्तमान में इस कोड के साथ AlertDialog की शैली सेट:AlertDialog.builder आइटम पृष्ठभूमि रंग

<style name="ListRow"> 
    <item name="android:background">@color/forest_green</item> 
    <item name="android:textSize">18sp</item> 
    <item name="android:textColor">@color/dialog_text</item> 
</style> 

enter image description here

+0

क्या इस कोड के साथ आपकी समस्या को वैसे भी है? –

+0

* थीम * पर 'android: background' का उपयोग न करें। सबकुछ जो इसकी पृष्ठभूमि को परिभाषित नहीं करता है वह हरा होगा। आपके बारे में 'एंड्रॉइड: बटनबार स्टाइल' और 'एंड्रॉइड: बटनबारबटन स्टाइल' के बजाय कैसे ओवरराइड करें? –

+0

आप इन ट्यूटोरियल पर एक नज़र डाल सकते हैं: http://blog.supenta.com/2014/07/02/how-to-style-alertdialogs-like-a-pro/ और http://www.materialdoc.com/अलर्ट/ – noongiya95

उत्तर

-1

इस

की तरह उपयोग styles.xml:

final AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.ListRow)); 

मेरी styles.xml में, मैं इस शैली है

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<style name="AlertDialogCustom" parent="@android:style/AlertDialog"> 
    <item name="android:textColor">#00FF00</item> 
    <item name="android:typeface">monospace</item> 
    <item name="android:textSize">10sp</item> 
</style> 

+3

क्या आपने पोस्ट करने से पहले इसे आजमाया था? यह संकलित भी नहीं करता है ... – moonlightcheese

+0

मैंने इस त्रुटि का उपयोग किया है: त्रुटि: आइटम के लिए अभिभावक को पुनर्प्राप्त करने में त्रुटि: कोई संसाधन नहीं मिला है जो दिए गए नाम '@android: style/AlertDialog' से मेल खाता है। –

0

आप कस्टम सेट इस तरह की तरह प्रोग्राम के रूप में देख सकते हैं ..

LayoutInflater inflater = getLayoutInflater(); 
View dialoglayout = inflater.inflate(R.layout.dialog_layout, (ViewGroup) getCurrentFocus()); 
AlertDialog.Builder builder = new AlertDialog.Builder(this); 
builder.setView(dialoglayout); 
builder.show(); 

हरे रंग की पृष्ठभूमि के साथ अपने लेआउट में dialog_layout.xml पैदा करते हैं।

0

यह मेरे लिए काम करता था। उनमें से सभी पृष्ठभूमि है।

final AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.ListRow)); 

builder.setIcon(android.R.drawable.ic_dialog_info).setTitle("welcome") 
     .setMessage("...") 
     .setPositiveButton("login", new DialogInterface.OnClickListener() { 
      @Override 
      public void onClick(DialogInterface dialog, int which) 
      { 
       Intent intent = new Intent(HomeActivity.this, LoginActivity.class); 
       startActivity(intent); 
      } 
     }).setNegativeButton("register", new DialogInterface.OnClickListener() { 
      @Override 
      public void onClick(DialogInterface dialog, int which) 
      { 
       Intent intent = new Intent(getApplicationContext(),RegisterActivity.class); 
       startActivity(intent); 
      } 
     }).show(); 
0

Theme.AppCompat.Dialog.Alert अभिभावक के रूप में साथ संवाद शैली को परिभाषित करें:

<style name="AlertDialog" parent="Theme.AppCompat.Dialog.Alert"> 
    <item name="android:background">@color/green</item> 
    ... 
</style> 

स्रोत: http://www.materialdoc.com/alerts/

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