diff options
author | Adam Powell <adamp@google.com> | 2011-11-08 09:47:32 -0800 |
---|---|---|
committer | Adam Powell <adamp@google.com> | 2011-11-08 09:49:21 -0800 |
commit | 42b7e99b11a5ab1cbc0beebe0b15e46bdf462dff (patch) | |
tree | c144828b0eb309ab54f5fd69293ed2e4c58c4dd7 /core | |
parent | 13194b16d071ce70453a49e9462cfbeb7460d633 (diff) | |
download | frameworks_base-42b7e99b11a5ab1cbc0beebe0b15e46bdf462dff.zip frameworks_base-42b7e99b11a5ab1cbc0beebe0b15e46bdf462dff.tar.gz frameworks_base-42b7e99b11a5ab1cbc0beebe0b15e46bdf462dff.tar.bz2 |
Fix bug 5544103 - Spinner text doesn't look dimmed when disabled
Pre-Holo spinners had a far more "buttony" look that expressed the
disabled state clearly, but Holo spinners are more subtle. As a result
we want to mark the contained view representing the current item as
disabled when the spinner itself is disabled.
Express this as a private framework style attribute that cannot be
changed at runtime.
Change-Id: Icff2ef2b8a3b1a96cbf00e4c75eda41a4dada7b3
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/widget/Spinner.java | 18 | ||||
-rwxr-xr-x | core/res/res/values/attrs.xml | 3 | ||||
-rw-r--r-- | core/res/res/values/styles.xml | 1 |
3 files changed, 22 insertions, 0 deletions
diff --git a/core/java/android/widget/Spinner.java b/core/java/android/widget/Spinner.java index 27d44bf..ec3790e 100644 --- a/core/java/android/widget/Spinner.java +++ b/core/java/android/widget/Spinner.java @@ -68,6 +68,7 @@ public class Spinner extends AbsSpinner implements OnClickListener { int mDropDownWidth; private int mGravity; + private boolean mDisableChildrenWhenDisabled; private Rect mTempRect = new Rect(); @@ -186,6 +187,9 @@ public class Spinner extends AbsSpinner implements OnClickListener { mPopup.setPromptText(a.getString(com.android.internal.R.styleable.Spinner_prompt)); + mDisableChildrenWhenDisabled = a.getBoolean( + com.android.internal.R.styleable.Spinner_disableChildrenWhenDisabled, false); + a.recycle(); // Base constructor can call setAdapter before we initialize mPopup. @@ -196,6 +200,17 @@ public class Spinner extends AbsSpinner implements OnClickListener { } } + @Override + public void setEnabled(boolean enabled) { + super.setEnabled(enabled); + if (mDisableChildrenWhenDisabled) { + final int count = getChildCount(); + for (int i = 0; i < count; i++) { + getChildAt(i).setEnabled(enabled); + } + } + } + /** * Describes how the selected item view is positioned. Currently only the horizontal component * is used. The default is determined by the current theme. @@ -398,6 +413,9 @@ public class Spinner extends AbsSpinner implements OnClickListener { addViewInLayout(child, 0, lp); child.setSelected(hasFocus()); + if (mDisableChildrenWhenDisabled) { + child.setEnabled(isEnabled()); + } // Get measure specs int childHeightSpec = ViewGroup.getChildMeasureSpec(mHeightMeasureSpec, diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index a40e24c..d0ab8b1 100755 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -3331,6 +3331,9 @@ <attr name="popupPromptView" format="reference" /> <!-- Gravity setting for positioning the currently selected item. --> <attr name="gravity" /> + <!-- Whether this spinner should mark child views as enabled/disabled when + the spinner itself is enabled/disabled. --> + <attr name="disableChildrenWhenDisabled" format="boolean" /> </declare-styleable> <declare-styleable name="DatePicker"> diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml index 949f01f..73e1a7c 100644 --- a/core/res/res/values/styles.xml +++ b/core/res/res/values/styles.xml @@ -1798,6 +1798,7 @@ please see styles_device_defaults.xml. <item name="android:dropDownWidth">wrap_content</item> <item name="android:popupPromptView">@android:layout/simple_dropdown_hint</item> <item name="android:gravity">left|center_vertical</item> + <item name="android:disableChildrenWhenDisabled">true</item> </style> <style name="Widget.Holo.Spinner.DropDown"> |