2016-09-14 14 views
12

मैंने उपयोगकर्ता की पुष्टि हटाने के लिए अलर्टडिअलॉग का उपयोग किया। मैं अपने डिवाइस (Android 5.1) पर जाँच करें और यह दिखाने के साथ-साथसंवाद सकारात्मक और नकारात्मक बटन नहीं दिखाता

enter image description here

लेकिन कुछ एक और डिवाइस (भी एंड्रॉयड 5.1 चलाने), संवाद सकारात्मक और नकारात्मक बटन याद किया पर।

enter image description here

मैं की और पाया कि उपकरणों इस मुद्दे हो एक मध्यम संकल्प (960x540, 854x480) है।

क्या संकल्प इस मुद्दे से संबंधित है? यदि नहीं, तो क्या आप मुझे कारण बता सकते हैं और इस समस्या को कैसे ठीक कर सकते हैं?

प्रदर्शन संवाद के लिए मेरे कोड:

public static final Dialog yesNoDialog(Context context, 
               String message, 
               DialogInterface.OnClickListener yesAction, DialogInterface.OnClickListener noAction) { 


      AlertDialog.Builder builder = new AlertDialog.Builder(context,R.style.todoDialogLight); 

      builder.setTitle(context.getString(R.string.app_name)) 
        .setMessage(message) 
        .setCancelable(false) 
        .setPositiveButton("YES", yesAction) 
        .setNegativeButton("NO", noAction); 
      return builder.create(); 
} 

और styles.xml

<style name="todoDialogLight" parent="Theme.AppCompat.Light.Dialog"> 

      <!-- Used for the buttons --> 
      <item name="colorAccent">@color/colorPrimaryDark</item> 
      <item name="android:textStyle">bold</item> 
      <!-- Used for the title and text --> 
      <item name="android:textColorPrimary">@color/colorText</item> 
      <!-- Used for the background --> 
      <!-- <item name="android:background">#4CAF50</item>--> 
      <item name="android:fontFamily">sans-serif</item> 
      <item  name="android:windowAnimationStyle">@style/RemindDialogAnimation</item> 
      <item name="android:layout_width">@dimen/width_remind_dialog</item> 
      <item name="android:layout_height">wrap_content</item> 
</style> 

उत्तर

0

यह वास्तव में संकल्प से संबंधित है, मैं सही कारण पता नहीं है और सिर्फ किसी और अगर एक बनाने के इस मुद्दे को ठीक करने की स्थिति।

public static String getDensity(Context context) { 
     float density = context.getResources().getDisplayMetrics().density; 
     if (density >= 4.0) { 
      return "xxxhdpi"; 
     } 
     if (density >= 3.0) { 
      return "xxhdpi"; 
     } 
     if (density >= 2.0) { 
      return "xhdpi"; 
     } 
     if (density >= 1.5) { 
      return "hdpi"; 
     } 
     if (density >= 1.0) { 
      return "mdpi"; 
     } 
     return "ldpi"; 
} 

AlertDialog

public static Dialog yesNoDialog(final Context context, 
               final String message, 
               final DialogInterface.OnClickListener yesAction, 
               final DialogInterface.OnClickListener noAction) { 
      int theme = PreferenceUtil.getThemeSetting(context, PreferenceUtil.PREF_THEME); 
      AlertDialog.Builder builder = null; 
      String density = AppUtil.getDensity(context); 
      if (theme == ThemeUtil.THEME_LIGHT) { 
       if(density.equals("hdpi")){ 
        builder = new AlertDialog.Builder(context); 
       }else{ 
        builder = new AlertDialog.Builder(context, R.style.todoDialogLight); 
       } 
      } else { 
       if(density.equals("hdpi")){ 
        builder = new AlertDialog.Builder(context); 
       }else{ 
        builder = new AlertDialog.Builder(context, R.style.todoDialogDark); 
       } 
      } 
      builder.setTitle(context.getString(R.string.app_name)) 
        .setMessage(message) 
        .setCancelable(false) 
        .setPositiveButton("YES", yesAction) 
        .setNegativeButton("NO", noAction); 
      return builder.create(); 
    } 

आशा है कि यह दूसरों के डेवलपर, जो एक ही समस्या है के लिए मदद करते हैं।

+0

यह सब क्या है? वरीयता कहाँ है? शैलियों "todoDialogLight" और "todoDialogDark" कहां हैं? कृपया मेरे उत्तर – usman

22

तो बटन मेरे लिए हैं। दुर्भाग्यवश, वे सफेद पृष्ठभूमि पर सफेद पाठ थे। इसका संकल्प करने के लिए कुछ भी नहीं है लेकिन आप जिस विषय को चुन रहे हैं उसके साथ अधिक कुछ करना है। इसे हल करने के लिए आपको अपने संवाद विषय में सही टेक्स्ट रंग सेट करने की आवश्यकता है।

उदाहरण के लिए, styles.xml में जोड़ने

<style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert"> 
<item name="colorPrimary">@color/colorPrimaryDarkBlue</item> 
</style> 

और अपनी गतिविधि में जोड़ने

AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MyActivity.this, R.style.MyDialogTheme); 

आशा इस मदद करता है।

+2

को मेरे लिए "colorAccent" में बदलकर सुधारें। – Ancee

2

अली के समाधान ने मेरे लिए काम किया। मेरा मूल कोड पिछले एंड्रॉइड संस्करण < पर काम करता था 7. लेकिन मेरे पिक्सेल पर परीक्षण ने अदृश्य बटन दिए। मैंने नीचे दिखाए गए अनुसार अली द्वारा विस्तृत शैली की अवधारणा को जोड़ा और सभी अच्छी तरह से हैं:

return new AlertDialog.Builder(getActivity(),R.style.MyDialogTheme) 
      .setView(v) 
      .setTitle(R.string.filter_picker_title) 
      .setPositiveButton(android.R.string.ok, 
        // when the user presses the button to select a new number 
        new DialogInterface.OnClickListener() { 
         @Override 
         public void onClick(DialogInterface dialog, int which) { 

          Integer markerIndex = mNumberPicker.getValue(); 
          stringFilter=uniqueValues[markerIndex]; 
          sendResult(Activity.RESULT_OK, stringFilter); 
         } 
        }) 
      .create(); 
0

संवाद संवाद;

public void startAlertDialog(String message) 
{ 
    AlertDialog.Builder alertDialog=new AlertDialog.Builder(this); 


    alertDialog.setCancelable(false); 

    LayoutInflater inflater=(LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE); 
    View view=inflater.inflate(R.layout.alertdialoglayout,null); 
    TextViewRagular textViewRagular=(TextViewRagular)view.findViewById(R.id.textviewMessage); 
    textViewRagular.setText(message); 
    alertDialog.setView(view); 
    dialog=alertDialog.create(); 
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 
    dialog.show(); 
} 
+0

Plz इस कोड को आजमाएं। वह कोड मेरे लिए काम करता था –

0

आप अपने styles.xml एक गहरे रंग के colorAccent का रंग सेट में एक कस्टम थीम उपयोग कर रहे हैं।

<!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimary</item> 
     <item name="colorAccent">@color/colorPrimary</item> 
    </style> 
1

शैली में इसे जोड़ें।xml:

<style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert"> 
     <item name="android:textColor">@color/colorAccent</item> 
</style> 

और गतिविधि उपयोग में

AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MyActivity.this, R.style.MyDialogTheme); 
संबंधित मुद्दे