浏览代码

You can now use negaitve and neutral buttons invidivually without a positive action. Action buttons must be explicitly shown by setting text.

Aidan Follestad 10 年之前
父节点
当前提交
876267beb4

+ 4 - 4
README.md

@@ -37,8 +37,8 @@ new MaterialDialog.Builder(this)
         .title("Use Google's Location Services?")
         .content("Let Google help apps determine location. This means sending anonymous location data to Google, even when no apps are running.")
         .theme(Theme.LIGHT)  // the default is light, so you don't need this line
-        .positiveText("Agree")  // the default for textual dialogs (not list or custom view dialogs) is 'OK'
-        .negativeText("Disagree")  // leaving this line out will remove the negative button
+        .positiveText("Agree")
+        .negativeText("Disagree")
         .build()
         .show();
 ```
@@ -59,7 +59,7 @@ Drawable d = // ... get from somewhere...
 new MaterialDialog.Builder(this)
         .title("Use Google's Location Services?")
         .content("Let Google help apps determine location. This means sending anonymous location data to Google, even when no apps are running.")
-        .positiveText("Agree")  // the default for textual dialogs (not list or custom view dialogs) is 'OK'
+        .positiveText("Agree")
         .icon(d)
         .build()
         .show();
@@ -237,7 +237,7 @@ new MaterialDialog.Builder(this)
 
 If you want to preselect item(s), pass an array of indices in place of null in `itemsCallbackSingleChoice()`.
 For an example, `new Integer[] { 2, 5 }`. If `autoDismiss` is turned off, then you must manually
-dismiss the dialog in the callback. Auto dismiss is on by default. When `positiveText()` is not used, the
+dismiss the dialog in the callback. Auto dismiss is on by default. When action buttons are not added, the
 callback will be called every time you select an item since no action is available to press, without the
 dialog being dismissed. You can pass `positiveText()` or the other action buttons to the builder to force
 it to display the action buttons below your list, however this is only useful in some specific cases.

+ 1 - 1
library/build.gradle

@@ -7,7 +7,7 @@ android {
 
     defaultConfig {
         applicationId "com.afollestad.materialdialogs"
-        minSdkVersion 9
+        minSdkVersion 14
         targetSdkVersion 21
         versionCode 1
         versionName "0.1.2"

+ 16 - 3
library/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

@@ -25,6 +25,7 @@ import android.widget.CheckBox;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.RadioButton;
+import android.widget.RelativeLayout;
 import android.widget.ScrollView;
 import android.widget.TextView;
 
@@ -375,7 +376,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
      * and sets their properties (such as height, text color, etc.).
      */
     private boolean invalidateActions() {
-        if (positiveText == null) {
+        if (!hasActionButtons()) {
             // If the dialog is a plain list dialog, no buttons are shown.
             view.findViewById(R.id.buttonDefaultFrame).setVisibility(View.GONE);
             view.findViewById(R.id.buttonStackedFrame).setVisibility(View.GONE);
@@ -428,6 +429,18 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
             negativeButton.setText(this.negativeText);
             negativeButton.setTag(NEGATIVE);
             negativeButton.setOnClickListener(this);
+
+            if (!isStacked) {
+                RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
+                        RelativeLayout.LayoutParams.WRAP_CONTENT,
+                        (int) getContext().getResources().getDimension(R.dimen.md_button_height));
+                if (this.positiveText != null) {
+                    params.addRule(RelativeLayout.LEFT_OF, R.id.buttonDefaultPositive);
+                } else {
+                    params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
+                }
+                negativeButton.setLayoutParams(params);
+            }
         } else {
             negativeButton.setVisibility(View.GONE);
         }
@@ -502,14 +515,14 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
                 if (!cb.isChecked())
                     cb.setChecked(true);
                 invalidateSingleChoice(index);
-                if (positiveText == null) {
+                if (!hasActionButtons()) {
                     // Immediately send the selection callback without dismissing if no action buttons are shown
                     sendSingleChoiceCallback(v);
                 }
             } else if (listCallbackMulti != null) {
                 CheckBox cb = (CheckBox) ((LinearLayout) v).getChildAt(0);
                 cb.setChecked(!cb.isChecked());
-                if (positiveText == null) {
+                if (!hasActionButtons()) {
                     // Immediately send the selection callback without dismissing if no action buttons are shown
                     sendMultichoiceCallback();
                 }

+ 2 - 2
library/src/main/res/layout/md_dialog.xml

@@ -128,10 +128,10 @@
             android:layout_alignParentLeft="true"
             android:layout_marginLeft="@dimen/md_neutral_button_margin" />
 
+        <!-- toLeftOf rule added from invalidateActions() -->
         <TextView
             android:id="@+id/buttonDefaultNegative"
-            style="@style/MD_ActionButton"
-            android:layout_toLeftOf="@+id/buttonDefaultPositive" />
+            style="@style/MD_ActionButton" />
 
         <TextView
             android:id="@+id/buttonDefaultPositive"

+ 2 - 2
sample/build.gradle

@@ -8,8 +8,8 @@ android {
         applicationId "com.afollestad.materialdialogssample"
         minSdkVersion 14
         targetSdkVersion 21
-        versionCode 31
-        versionName "0.1.2"
+        versionCode 32
+        versionName "0.2.0"
     }
     buildTypes {
 //        release {

+ 8 - 8
sample/src/main/java/com/afollestad/materialdialogssample/MainActivity.java

@@ -132,8 +132,8 @@ public class MainActivity extends ActionBarActivity {
     private void showBasicNoTitle() {
         new MaterialDialog.Builder(this)
                 .content(R.string.shareLocationPrompt)
-                .positiveText(R.string.agree)  // the default is 'Accept', this line could be left out
-                .negativeText(R.string.disagree)  // leaving this line out will remove the negative button
+                .positiveText(R.string.agree)
+                .negativeText(R.string.disagree)
                 .build()
                 .show();
     }
@@ -142,8 +142,8 @@ public class MainActivity extends ActionBarActivity {
         new MaterialDialog.Builder(this)
                 .title(R.string.useGoogleLocationServices)
                 .content(R.string.useGoogleLocationServicesPrompt)
-                .positiveText(R.string.agree)  // the default is 'Accept', this line could be left out
-                .negativeText(R.string.disagree)  // leaving this line out will remove the negative button
+                .positiveText(R.string.agree)
+                .negativeText(R.string.disagree)
                 .build()
                 .show();
     }
@@ -152,8 +152,8 @@ public class MainActivity extends ActionBarActivity {
         new MaterialDialog.Builder(this)
                 .title(R.string.useGoogleLocationServices)
                 .content(R.string.loremIpsum)
-                .positiveText(R.string.agree)  // the default is 'Accept', this line could be left out
-                .negativeText(R.string.disagree)  // leaving this line out will remove the negative button
+                .positiveText(R.string.agree)
+                .negativeText(R.string.disagree)
                 .build()
                 .show();
     }
@@ -163,8 +163,8 @@ public class MainActivity extends ActionBarActivity {
                 .icon(R.drawable.ic_launcher)
                 .title(R.string.useGoogleLocationServices)
                 .content(R.string.useGoogleLocationServicesPrompt)
-                .positiveText(R.string.agree)  // the default is 'Accept', this line could be left out
-                .negativeText(R.string.disagree)  // leaving this line out will remove the negative button
+                .positiveText(R.string.agree)
+                .negativeText(R.string.disagree)
                 .build()
                 .show();
     }