2013-02-16 56 views
42

मैंने जेली बीन को लक्षित, ग्रहण में एक नया एप्लिकेशन बनाया। यह सब स्वचालित रूप से बनाया गया कोड है। प्रकट सेट AppName के लिए आवेदन विषय:एंड्रॉइड डायलॉग थीम आइकन को बहुत हल्का बनाता है

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    . . . 

जो मूल्यों dir में शैलियों के लिए AppBaseTheme करने के लिए अनुवाद:

<resources xmlns:android="http://schemas.android.com/apk/res/android"> 

    <!-- 
     Base application theme, dependent on API level. This theme is replaced 
     by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 
    --> 
    <style name="AppBaseTheme" parent="android:Theme.Light"> 
     <!-- 
      Theme customizations available in newer API levels can go in 
      res/values-vXX/styles.xml, while customizations related to 
      backward-compatibility can go here. 
     --> 
    </style> 

    <!-- Application theme. --> 
    <style name="AppTheme" parent="AppBaseTheme"> 
     <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
    </style> 

</resources> 

और मूल्यों v14/styles.xml है:

<resources> 

    <!-- 
     Base application theme for API 14+. This theme completely replaces 
     AppBaseTheme from BOTH res/values/styles.xml and 
     res/values-v11/styles.xml on API 14+ devices. 
    --> 
    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar"> 
     <!-- API 14 theme customizations can go here. --> 
    </style> 

</resources> 

मैंने छोड़ने से पहले एक पुष्टिकरण संवाद बॉक्स बनाया:

case R.id.menu_quit: 
     new AlertDialog.Builder(this) 
     .setIcon(android.R.drawable.ic_dialog_alert) 
     .setTitle(R.string.confirm_title) 
     .setMessage(R.string.confirm_text) 
     .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { 
      @Override 
      public void onClick(DialogInterface dialog, int which) { 
       finish();  
      } 

और जिसके परिणामस्वरूप संवाद बॉक्स है:

resulting dialog box

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

ठीक
साथ संपादित Tomik की जानकारी के बाद मैं android.R.attr.alertDialogIcon के लिए दस्तावेज़ पढ़ सकते हैं और यह सुधार (प्रतिस्थापित setIcon()setIconAttribute() के साथ)

 new AlertDialog.Builder(this) 
     .setIconAttribute(android.R.attr.alertDialogIcon) 
     .setTitle(R.string.confirm_title) 
     .setMessage(R.string.confirm_text) 
     .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { 
बनाया

अब संवाद इस तरह दिखता है:

enter image description here

उत्तर

43

समस्या यह है कि आप निजी संसाधन android.R.drawable.ic_dialog_alert का उपयोग कर रहे हैं।

निजी संसाधनों का उपयोग समस्याग्रस्त है, वे विभिन्न उपकरणों पर भिन्न हो सकते हैं और आप यह भी सुनिश्चित नहीं कर सकते कि वे सभी उपकरणों पर मौजूद हैं। निजी संसाधनों का उपयोग करने से बचने के लिए सबसे अच्छा है। अगर आपको उनकी ज़रूरत है, तो आपको उन्हें एंड्रॉइड स्रोतों से कॉपी करना चाहिए और उन्हें अपने प्रोजेक्ट के संसाधनों में रखना चाहिए।

आपका संसाधन बहुत सफेद क्यों है इसका सटीक कारण यह है कि आप संसाधन () का उपयोग कर रहे हैं जिसका उपयोग मानक (गैर-होलो) थीम के लिए किया जाता है।
लेकिन एंड्रॉइड 4.x (एपीआई स्तर 14) चलाने वाले उपकरणों के लिए आप होलो थीम (android:Theme.Holo.Light.DarkActionBar) का उपयोग कर रहे हैं जो आम तौर पर विभिन्न संसाधनों का उपयोग कर रहा है।

होलो थीम के साथ अंधेरे विषय के लिए डिफ़ॉल्ट चेतावनी आइकन android.R.id.ic_dialog_alert_holo_dark है या प्रकाश विषय के लिए android.R.id.ic_dialog_alert_holo_light (आपका मामला, आपको इसके बजाय इस संसाधन का उपयोग करना चाहिए)।

नोट: चूंकि एपीआई स्तर 11 के बाद एक विशेषता android.R.attr.alertDialogIcon है जो वर्तमान थीम के लिए डिफ़ॉल्ट अलर्ट संवाद आइकन को संदर्भित करती है। अपने कोड में आप इसे इस तरह से उपयोग कर सकते हैं:

case R.id.menu_quit: 
    new AlertDialog.Builder(this) 
    .setIconAttribute(android.R.attr.alertDialogIcon) 
    .setTitle(R.string.confirm_title) 
    .setMessage(R.string.confirm_text) 
    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int which) { 
      finish();  
     } 

फिर भी मैं क्योंकि कि एक ही रास्ता आप सुनिश्चित करें कि आइकन हमेशा ही दिखाई देगा हो सकता है अपनी परियोजना के संसाधनों तक एंड्रॉयड स्रोतों से संसाधन कॉपी करने के लिए सलाह देते हैं।

+0

अपनी टिप्पणी के बाद मैं जानकारी पढ़ सकते हैं और कोड को ठीक। परिणाम को प्रतिबिंबित करने के लिए मैं शीघ्र ही प्रश्न अपडेट कर दूंगा। ::: बीटीडब्लू मैं चिंतित नहीं हूं कि आइकन हमेशा एक जैसा दिखना चाहिए, बस वे दिखाई दे सकते हैं। – ilomambo

+0

जानकारी संवाद के बारे में क्या? वहां भी इसी तरह '.setIconAttribute (android.R.attr। ????) है' '.setIcon (android.R.drawable.ic_dialog_info) के स्थान पर उपयोग करने के लिए' – JFar

1

एक पूर्व-HC के लिए Tomik's answer के आधार पर workround आप भी उन उपकरणों पर प्रकाश विषय उपयोग कर रहे हैं:

AlertDialog.Builder builder = ...; 
if (VERSION.SDK_INT < VERSION_CODES.HONEYCOMB) { 
    Drawable icon = ContextCompat.getDrawable(context, android.R.drawable.ic_dialog_alert).mutate(); 
    icon.setColorFilter(new ColorMatrixColorFilter(new float[] { 
      -1, 0, 0, 0, 255, // red = 255 - red 
      0, -1, 0, 0, 255, // green = 255 - green 
      0, 0, -1, 0, 255, // blue = 255 - blue 
      0, 0, 0, 1, 0  // alpha = alpha 
    })); 
    builder.setIcon(icon); 
} else { 
    builder.setIconAttribute(android.R.attr.alertDialogIcon); 
}