2015-03-20 11 views
7

मैं स्टैक्ड पूर्ण-चौड़ाई बटनसामग्री डिजाइन बटन

के लिए नई सामग्री डिजाइन संवाद लागू करने के लिए एक उदाहरण कोड को खोजने के लिए कोशिश कर रहा हूँ

किसी ने मुझे एक उदाहरण कोड enter image description here

+0

यह पृष्ठ देखें [यहां] (https://github.com/lewisjdeane/L-Dialogs) – Harry

उत्तर

4

मैं के साथ मदद कर सकते हैं 'इस का उपयोग कर रहा हूँ और यह मेरे लिए महान काम करता है:

https://github.com/afollestad/material-dialogs

यहाँ एक डेमो है: https://play.google.com/store/apps/details?id=com.afollestad.materialdialogssample (खड़ी बटन सहित)

+0

क्या यह पीछे भी संगत होगा? – user3722531

+0

हां: "एक सुंदर [...] संवाद API, आपको एंड्रॉइड के सभी संस्करणों (AppCompat के विपरीत) में सामग्री डिज़ाइन थीम वाले संवाद का उपयोग करने में सक्षम बनाता है। मैं केवल एंड्रॉइड 4.x और उच्चतर के लिए इसका उपयोग कर रहा हूं लेकिन यह पुराने संस्करणों पर भी काम करता है। –

+0

क्या इस तरह की लाइब्रेरी आयात किए बिना मैं ऐसा कर सकता हूं? – user3722531

6

आप का उपयोग केवल AppCompat, मेरे वैकल्पिक हल जाँच के साथ कि प्राप्त कर सकते थे:

कोड आयात android.support.v7.app.AlertDialog;

AlertDialog.Builder builder; 
    builder = new AlertDialog.Builder(context, R.style.StackedAlertDialogStyle); 
    builder.setTitle("Title"); 
    builder.setMessage("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc dignissim purus eget gravida mollis. Integer in auctor turpis. Morbi auctor, diam eget vestibulum congue, quam arcu pulvinar dui, blandit egestas erat enim non ligula." + 
      " Nunc quis laoreet libero. Aliquam consectetur nibh eu arcu eleifend efficitur."); 
    builder.setPositiveButton("Positive Button", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int which) { 
     } 
    }); 
    builder.setNeutralButton("Neutral Button", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int which) { 
     } 
    }); 
    builder.setNegativeButton("Cancel Button", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int which) { 
     } 
    }); 
    AlertDialog alertDialog = builder.create(); 
    alertDialog.show(); 
     try{ 
      final Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); 
      LinearLayout linearLayout = (LinearLayout) button.getParent(); 
      linearLayout.setOrientation(LinearLayout.VERTICAL); 
     } catch(Exception ex){ 
      //ignore it 
     } 

शैली

<style name="StackedAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert"> 
    <item name="buttonBarButtonStyle">@style/StackedButtonBarButtonStyle</item> 
</style> 

<style name="StackedButtonBarButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog"> 
    <item name="android:layout_gravity">right</item> 
</style> 

परिणाम

Stacked Alert Dialog

+1

यह एक बहुत अच्छा विचार नहीं है। सबसे पहले, संवाद के लेआउट की धारणा है, जो आंतरिक है और बदल सकती है। दूसरा, ऐप कॉम्पैप के कार्यान्वयन से पता चलता है कि alertDialog.getButton शून्य लौटाता है क्योंकि बटन केवल शो() फ़ंक्शन पर सेट होते हैं, जिसके द्वारा यह तर्क संवाद लेआउट को प्रभावित नहीं करेगा – rajath

+2

बहुत अच्छा नहीं है, क्या एंड्रॉइड एसडीके है, एपीआई प्रदान नहीं करता है सामग्री दिशानिर्देशों के अनुसार अलर्ट संवाद को संशोधित करने के लिए।बेशक आंतरिक कार्यान्वयन बदला जा सकता है, लेकिन यदि आप एपकोपेट संस्करण अपडेट करेंगे, तो आपको यह जांचना होगा कि अपडेट के बाद यह संवाद ठीक काम करेगा - लेकिन यह कामकाज है और इसमें सीमाएं हो सकती हैं। –

+0

मैं एपकोपेट v24.0.0.0 का उपयोग कर रहा हूं, ऐसा लगता है कि पाठ लंबे समय तक स्वचालित रूप से बटन को लंबवत रूप से ढेर करता है। – Bruce

1

यहाँ है कैसे मैं केवल AppCompat लाइब्रेरी का उपयोग कर मेरे एप्लिकेशन में कर रहा हूँ आप कर सकते हैं विकल्प

String[] mOptionsArray = new String[]{"Option 1", "Option 2"}; 
@Override 
public Dialog onCreateDialog(Bundle savedInstanceState) { 
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); 
    builder.setTitle("Cool! title"); 
    builder.setMessage("Cool! message"); 

    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View view = inflater.inflate(R.layout.dialog_list_view, null); 
    ListView listView = (ListView) view.findViewById(R.id.list_view); 
    listView.setAdapter(new ArrayAdapter<>(
      getContext(), 
      R.layout.dialog_list_item, 
      R.id.button, 
      mOptionsArray 
    )); 
    listView.setDivider(null); 
    listView.setOnItemClickListener(mOnItemClickListener); 
    builder.setView(view); 

    return builder.create(); 
} 

dialog_list_view.xml

<?xml version="1.0" encoding="utf-8"?> 
<ListView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/list_view" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingBottom="8dp" 
    android:paddingLeft="16dp" 
    android:paddingRight="16dp" /> 

dialog_list_item.xml

<?xml version="1.0" encoding="utf-8"?> 
<Button xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/button" 
    style="@style/Widget.AppCompat.Button.Borderless.Colored" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@null" 
    android:clickable="false" 
    android:focusable="false" 
    android:gravity="right|center_vertical" 
    android:paddingRight="8dp" 
    android:paddingLeft="8dp" 
    android:text="Button" 
    android:textAllCaps="true" /> 

रेफरी के किसी भी संख्या: http://www.materialdoc.com/flat-button/, https://material.io/guidelines/components/dialogs.html#dialogs-specs, https://material.io/guidelines/components/buttons.html#buttons-style

Dialog with stacked full-width buttons

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