मैं कस्टम लेआउट के साथ एक AlertDialog उपयोग कर रहा हूँ। लेआउट में टेक्स्ट व्यू का रंग काला है, इसलिए होलो के साथ एंड्रॉइड 4.0 पर संवाद खोलते समय। लाइट, टेक्स्ट दिखाई दे रहा है। हालांकि अगर आप एंड्रॉइड 2.2 में संवाद खोलते हैं तो ग्रे ग्रे पृष्ठभूमि की वजह से पाठ दिखाई नहीं देता है। क्या पृष्ठभूमि रंग बदलने का कोई तरीका है?AlertDialog पृष्ठभूमि रंग
उत्तर
बस एक रंग है कि आप चाहते हैं करने के लिए अपने संवाद के लिए layout.xml फ़ाइल में जड़ दृश्य की पृष्ठभूमि परिभाषित करते हैं।
इस तरह:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/dialog_background" >
...
यह संवाद के मुख्य निकाय के लिए ठीक काम करता है, लेकिन शीर्षक बटन के साथ शीर्षक और पाद लेख वाला शीर्षलेख अभी भी सिस्टम "अंधेरा" रंग (ओएस 2.3 के लिए) परिभाषित है। –
AlertDialog.Builder.setView(getLayoutInflater().inflate(R.layout.your_layout, null));
इस फ़ंक्शन का उपयोग करके आप अपनी बातचीत में एक लेआउट बढ़ा सकते हैं। लेआउट xml में जो भी आप चाहते हैं अब करें। उदाहरण के लिए निम्नलिखित कोड देखें।
AlertDialog.Builder about = new AlertDialog.Builder(this);
about.setTitle(getString(name));
about.setIcon(R.drawable.icon);
about.setView(getLayoutInflater().inflate(R.layout.your_layout, null));
लेकिन यदि आप Android 2.2 पाठ में संवाद खोलने धूसर पृष्ठभूमि की वजह से दिखाई नहीं देता है। क्या पृष्ठभूमि रंग बदलने का कोई तरीका है?
हाँ यह संभव है, मैंने इसे डायलॉगबिल्डर का उपयोग करके अपने ऐप पर इस्तेमाल किया। बस अपने संवाद बिल्डर पर सच
builder.setInverseBackgroundForced(true);
AlertDialog dialog = builder.create();
dialog.show();
को inverseBackgroundForced डाल दिया। यह फ्रायओ से पहले एंड्रॉइड संस्करण पर पृष्ठभूमि को सफेद रंग (अंधेरे भूरे रंग के बजाय) पर मजबूर करेगा।
दृश्य की पृष्ठभूमि को सेट करने से क्लीनर जोड़ा जा रहा है (यह दृश्य को सफेद दिखाएगा लेकिन इसके आस-पास सभी ग्रे होंगे)। मैं इस सवाल को खोजने से पहले कुछ समय के लिए कोशिश कर रहा था। धन्यवाद। :) – Sufian
स्वीकार्य उत्तर के समान, मैं यहां टिप्पणी कर सकता हूं: यह संवाद के मुख्य निकाय के लिए ठीक काम करता है, लेकिन शीर्षक बटन के साथ शीर्षक और पाद लेख वाला शीर्षलेख अभी भी सिस्टम "अंधेरा" रंग (ओएस 2.3 के लिए) परिभाषित है। –
यह मेरे लिए काम किया, धन्यवाद बहुत – Naruto
आप StinePike और Artjom बी
StinePike के विचार बहुत अच्छा है करने के लिए बहुत बहुत धन्यवाद।
मैं एक स्वनिर्धारित पृष्ठभूमि होने AlertDialog में एक TextView डाल दिया।
मैं कैसे वस्तुओं अनुकूलित करने के लिए ठोस और ढाल पृष्ठभूमि का उपयोग करने के दिखा।
कृपया मुझे आप किस संदर्भ में मैं StinePike के आइडिया लागू किया पेश करने के लिए करते हैं।
// स्थान: MainActivity.java
AlertDialog mAlertDialog_With_Radio_Buttons;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ini();
}
public void onAlert_With_Radio_Buttons_Close_Click(View view) {
mAlertDialog_With_Radio_Buttons.dismiss();
} // onAlert_With_Radio_Buttons_Close_Click
public void alert_with_radio_buttons(){
AlertDialog.Builder
mAlertDialog_Builder = new AlertDialog.Builder(this);
mAlertDialog_Builder
.setView(getLayoutInflater()
.inflate(R.layout.alert_with_radio_buttons, null));
mAlertDialog_Builder
.setTitle("Select The Directory");
mAlertDialog_With_Radio_Buttons = mAlertDialog_Builder.create();
mAlertDialog_With_Radio_Buttons.show();
} // public void alert_with_radio_buttons(){
// location: alert_with_radio_buttons.xml in layout
<LinearLayout
android:id="@+id/alert_with_radio_buttons_tv_ll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/turquoise1"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<TextView
android:id="@+id/mAlert_With_Radio_Buttons_TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:background="@color/turquoise2"
android:textSize="@dimen/main_wiz_size"
android:text = "@string/alert_with_rb_tv_text" />
</LinearLayout>
// Location: colors in values
<color name="turquoise1">#FF00ABAB</color>
<color name="turquoise2">#FF00BCBC</color>
// Location: strings in values
<string name="alert_with_rb_tv_text">Directory Names</string>
// Close Definition
// location: alert_with_radio_buttons.xml in layout
<Button
android:id="@+id/alert_with_radio_buttons_close_btn"
android:text="@string/alert_with_radio_buttons_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_decor"
android:onClick="onAlert_With_Radio_Buttons_Close_Click" />
// location: btn_decor.xml in drawable
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true">
<gradient
android:startColor="#700000ff"
android:endColor="#70009B80"
android:angle="-90"/>
</shape>
location: strings.xml in values
<string name="alert_with_radio_buttons_close">Close</string>
आपकी मदद के लिए बहुत बहुत धन्यवाद। मैंने विषय में अपना उत्तर रखने के लिए एक अनुकूलित पृष्ठभूमि रखने वाले AlertDialog में एक टेक्स्ट व्यू डाला। मैं सलाह के अपने उत्कृष्ट टुकड़े "अकेले खड़े जवाब" गिर गया। कृपया मेरी टिप्पणी के बगल में एक छवि डालने के तरीके को जानने में मेरी सहायता करें। –
"वहाँ पृष्ठभूमि का रंग बदलने के लिए एक रास्ता है?" हां अलग-अलग संदर्भों के लिए कई तरीके हैं।
कृपया मुझे "विवरण प्रदान और मेरे अनुसंधान का हिस्सा" करने के लिए आप के लिए करते हैं। मेरे कोड दिखाता है कि कैसे प्राप्त करने के लिए ListView के आइटम चेतावनी संवाद में शामिल के लिए अनुकूलित TextView पृष्ठभूमि। लेआउट
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/layer_border">
<TextView
android:id="@+id/text_view_for_lv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity ="center"
android:padding ="5dip"
android:background="@color/turquoise2"
android:textSize="@dimen/lv_text_size"
android:textColor="@color/blue0"/>
</LinearLayout>
// location: main_activity.xml in layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/decor"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/main_activity_files_btn_ll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/layer_border" >
<Button
android:text="Files"
android:id="@+id/files_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_decor"
android:onClick="onMainActivity_Files_Click" />
</LinearLayout>
</LinearLayout>
// location: colors.xml in values
<color name="blue0">#0000FF</color>
<color name="turquoise2">#FF00BCBC</color>
// location: dimens.xml in values
<dimen name="lv_text_size">24dp</dimen>
// location: layer_border.xml in drawable
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="1dp" android:color="#9999FF" />
<solid android:color="#CCCCFF" />
<padding android:left ="4dp" android:top="4dp"
android:right="4dp" android:bottom="4dp" />
<corners android:radius="4dp" />
</shape>
// location: decor.xml in drawable
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true">
<gradient
android:startColor="#aa0000ff"
android:endColor="#aa009B80"
android:angle="-90"/>
</shape>
// location: MainActivity.java
ListView mListView;
AlertDialog mAlertDialog;
ArrayAdapter<String> mArrayAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mListView = new ListView(this);
ArrayList<String>
mArrayList_Days = new ArrayList<>();
for(int i = 0; i< 32; i++)
mArrayList_Days.add("Day " + String.valueOf(i));
mArrayAdapter = new ArrayAdapter<>(
this, R.layout.customized_tv_for_list_view,
R.id.text_view_for_lv, mArrayList_Days);
mListView.setAdapter(mArrayAdapter);
mListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String sel_item = (String) mListView
.getItemAtPosition(position);
Toast.makeText(MainActivity.this, sel_item, Toast.LENGTH_SHORT).show();
mAlertDialog.cancel();
} // onItemClick
}); // .setOnItemClickListener
build_files_alert_dialog();
}
public void build_files_alert_dialog() {
AlertDialog.Builder
mAlertBuilder = new AlertDialog.Builder(MainActivity.this);
mAlertBuilder.setTitle("Days");
mAlertBuilder.setView(mListView);
mAlertDialog = mAlertBuilder.create();
WindowManager.LayoutParams mLayoutParams = new WindowManager.LayoutParams();
mLayoutParams.copyFrom(mAlertDialog.getWindow().getAttributes());
}
public void onMainActivity_Files_Click(View view) {
mAlertDialog.show();
} // onMainActivity_Files_Click
- 1. AlertDialog
- 2. NavigationBar बदलें रंग (पृष्ठभूमि रंग)
- 3. AlertDialog
- 4. AlertDialog
- 5. पृष्ठभूमि रंग = बटन: IE
- 6. बदलें पृष्ठभूमि रंग WPF
- 7. ग्रहण शासक पृष्ठभूमि रंग
- 8. jQuery पृष्ठभूमि रंग एनीमेशन
- 9. विम पृष्ठभूमि रंग
- 10. UITableView पृष्ठभूमि रंग
- 11. बदलें टीआर पृष्ठभूमि रंग
- 12. एक्शनबैरशेलॉक पृष्ठभूमि रंग बदलें
- 13. विभिन्न पृष्ठभूमि रंग
- 14. चयनित पंक्ति पृष्ठभूमि रंग
- 15. पृष्ठभूमि रंग बदलें
- 16. पृष्ठभूमि: रंग आईई 8
- 17. MPMoviePlayerController पृष्ठभूमि रंग
- 18. रिमोटव्यू framelayout पृष्ठभूमि रंग
- 19. निष्क्रिय नियंत्रण पृष्ठभूमि रंग
- 20. UIView पृष्ठभूमि रंग
- 21. सीएसएस अस्पष्टता - पृष्ठभूमि रंग
- 22. div पृष्ठभूमि रंग, ऑनहोवर
- 23. NSImageView + पृष्ठभूमि रंग
- 24. डिफ़ॉल्ट अधिसूचना पृष्ठभूमि रंग
- 25. यूआईबटन पृष्ठभूमि रंग बदलना
- 26. UIWebView पृष्ठभूमि रंग
- 27. पृष्ठभूमि छवि और रंग
- 28. टोस्ट पृष्ठभूमि रंग करके
- 29. JTable पृष्ठभूमि रंग
- 30. एंड्रॉइड वेबव्यू पृष्ठभूमि रंग
से customized_tv_for_list_view.xml एक xml फ़ाइल में अपने कस्टम लेआउट घोषित और की तुलना में सिर्फ अपने संवाद के लिए दृश्य सेट:
के
// स्थान ListView के आइटम के लिए मॉडल के साथ शुरू करते हैं। – hardartcore
आप कस्टम DlertDilaog बना सकते हैं। [यह] देखें (http://stackoverflow.com/a/5392617)। – burnO