केंद्र के लिए मैं एंड्रॉयड (जावा) प्रोग्रामिंग के लिए इस कोड का उपयोग बटन? जैसा कि आप देखते हैं मैं Gravity.CENTER_HORIZONTAL
(.CENTER
) का उपयोग करके बटन को सेंसर करने के लिए संरेखित करने का प्रयास करता हूं लेकिन कुछ भी नहीं बदलता है। बटन लगभग सही स्थिति में है।संरेखित AlertDialog
उत्तर
यह मेरे लिए काम किया:
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle);
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(message);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
final AlertDialog dialog = builder.create();
dialog.show(); //show() should be called before dialog.getButton().
final Button positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
LinearLayout.LayoutParams positiveButtonLL = (LinearLayout.LayoutParams) positiveButton.getLayoutParams();
positiveButtonLL.gravity = Gravity.CENTER;
positiveButton.setLayoutParams(positiveButtonLL);
मुझे लगता है कि आप समर्थन लाइब्रेरी से AlertDialog का उपयोग कर रहे हैं।
यदि ऐसा है तो अपने आयात को android.app.AlertDialog पर बदलने का प्रयास करें।
उपयोग crtn की विधि, लेकिन इसके बजाय LayoutParam के गुरुत्वाकर्षण बदलने की, ViewGroup.LayoutParams.MATCH_PARENT को इसकी चौड़ाई बदलने;
यह काम कर रहा है, धन्यवाद –
ठीक काम करता है। मेरे जैसे आलसी लोगों के लिए superclear होने के लिए: <सकारात्मकButtonLL.gravity = Gravity.CENTER;><सकारात्मकButtonLL.width = ViewGroup.LayoutParams.MATCH_PARENT;> के साथ लाइन को बदलें। –
android.support.v7.app.AlertDialog
का उपयोग करें जो आपके सकारात्मक और नकारात्मक बटन को केंद्र में संरेखित करेगा।
android.app.AlertDialog
नीचे दिए गए बटन को नीचे 16 डीपी स्पेस छोड़कर शीर्ष पर रखा जाएगा।
क्रेटन की विधि और स्कॉट ब्राउन के संशोधन की कोशिश की, दोनों ने मुझे यह पसंद नहीं किया कि मुझे कैसा लगा।
crtn के समाधान बिल्कुल मेरे लिए बटन की उपस्थिति परिवर्तन नहीं किया (मैं android.R.style.Theme_Material_Light_Dialog
उपयोग कर रहा हूँ) और स्कॉट ब्राउन के समाधान मेरी सकारात्मक बटन संवाद माता पिता के किनारे अतीत का विस्तार कर दिया।
Theme_Material_Light_Dialog
के लिए बटन LinearLayout
उपclass के भीतर निहित हैं जो बटन को दाएं करने के लिए अपने दूसरे (अनुक्रमणिका 1) तत्व के रूप में रिक्त दृश्य का उपयोग करता है।
मैं Button
रेफरी हड़पने crtn की तरह कार्य करता है:
AlertDialog dialog = bld.create();
dialog.show(); //show() MUST be called before dialog.getButton
Button positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
लेकिन तब मैं CENTER_HORIZONTAL
को View.GONE को leftSpacer और माता पिता के गुरुत्वाकर्षण सेटLinearLayout parent = (LinearLayout) positiveButton.getParent();
parent.setGravity(Gravity.CENTER_HORIZONTAL);
View leftSpacer = parent.getChildAt(1);
leftSpacer.setVisibility(View.GONE);
यह लाभ ऐसा नहीं है कि है संवाद के बटन स्टैकिंग व्यवहार को तोड़ना नहीं है। नुकसान यह है कि यदि आंतरिक लेआउट बदलता है, तो यह टूट जाएगा, इसलिए वाईएमएमवी।
आप एक ही समय (बड़े & सेंटर) में सकारात्मक और नकारात्मक बटन करना चाहते हैं, तो आप कुछ इस तरह का उपयोग कर सकते हैं:
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Title");
alertDialog.setMessage("Message");
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
Button btnPositive = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
Button btnNegative = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) btnPositive.getLayoutParams();
layoutParams.weight = 10;
btnPositive.setLayoutParams(layoutParams);
btnNegative.setLayoutParams(layoutParams);
- 1. AlertDialog
- 2. AlertDialog
- 3. AlertDialog
- 4. एंड्रॉइड AlertDialog
- 5. एक AlertDialog
- 6. कैसे AlertDialog
- 7. गतिविधि AlertDialog
- 8. AlertDialog setOnDismissListener
- 9. एंड्रॉयड: AlertDialog
- 10. एंड्रॉइड: टेक्स्ट को AlertDialog
- 11. फ़ॉन्ट आकार को AlertDialog
- 12. दिखाएँ AlertDialog MvvmCross
- 13. AlertDialog बटन शैली
- 14. AlertDialog और .setAdapter
- 15. AlertDialog बनाम AlertDialog.Builder
- 16. AlertDialog पृष्ठभूमि रंग
- 17. संसाधन $ NotFoundException: AlertDialog
- 18. AlertDialog एक सूची
- 19. संरेखित आइटम, संरेखित आत्म IE11
- 20. दिखा Android Wear शैली AlertDialog
- 21. एंड्रॉइड UncaughtExceptionHandler जो AlertDialog ब्रेक
- 22. ताज़ा या बदलने AlertDialog संदेश
- 23. AlertDialog setCustomTitle स्टाइलिंग मानक AlertDialog शीर्षक से मिलान करने के लिए
- 24. संरेखित तत्वों
- 25. संरेखित आर
- 26. वरीयता स्क्रीन से AlertDialog कैसे खोलें?
- 27. एक फ़ंक्शन में AlertDialog जिसमें वापसी मूल्य
- 28. क्या विस्तारणीय सूची AlertDialog बनाना संभव है?
- 29. स्टेटिक तरीके के साथ AlertDialog बनाना?
- 30. Android में AlertDialog का परीक्षण कैसे करें?
संदर्भ 'positiveBtn' क्या है? – t0m
क्या यह वास्तव में काम करता है? – zygimantus
एंड्रॉइड 7.1.1 पर काम नहीं करता है लेकिन नीचे @ स्कोट ब्राउन का समाधान ठीक काम करता है। – mtronics