Skip to content

Commit 42b7e99

Browse files
committed
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
1 parent 13194b1 commit 42b7e99

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

core/java/android/widget/Spinner.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public class Spinner extends AbsSpinner implements OnClickListener {
6868
int mDropDownWidth;
6969

7070
private int mGravity;
71+
private boolean mDisableChildrenWhenDisabled;
7172

7273
private Rect mTempRect = new Rect();
7374

@@ -186,6 +187,9 @@ public Spinner(Context context, AttributeSet attrs, int defStyle, int mode) {
186187

187188
mPopup.setPromptText(a.getString(com.android.internal.R.styleable.Spinner_prompt));
188189

190+
mDisableChildrenWhenDisabled = a.getBoolean(
191+
com.android.internal.R.styleable.Spinner_disableChildrenWhenDisabled, false);
192+
189193
a.recycle();
190194

191195
// Base constructor can call setAdapter before we initialize mPopup.
@@ -196,6 +200,17 @@ public Spinner(Context context, AttributeSet attrs, int defStyle, int mode) {
196200
}
197201
}
198202

203+
@Override
204+
public void setEnabled(boolean enabled) {
205+
super.setEnabled(enabled);
206+
if (mDisableChildrenWhenDisabled) {
207+
final int count = getChildCount();
208+
for (int i = 0; i < count; i++) {
209+
getChildAt(i).setEnabled(enabled);
210+
}
211+
}
212+
}
213+
199214
/**
200215
* Describes how the selected item view is positioned. Currently only the horizontal component
201216
* is used. The default is determined by the current theme.
@@ -398,6 +413,9 @@ private void setUpChild(View child) {
398413
addViewInLayout(child, 0, lp);
399414

400415
child.setSelected(hasFocus());
416+
if (mDisableChildrenWhenDisabled) {
417+
child.setEnabled(isEnabled());
418+
}
401419

402420
// Get measure specs
403421
int childHeightSpec = ViewGroup.getChildMeasureSpec(mHeightMeasureSpec,

core/res/res/values/attrs.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3331,6 +3331,9 @@
33313331
<attr name="popupPromptView" format="reference" />
33323332
<!-- Gravity setting for positioning the currently selected item. -->
33333333
<attr name="gravity" />
3334+
<!-- Whether this spinner should mark child views as enabled/disabled when
3335+
the spinner itself is enabled/disabled. -->
3336+
<attr name="disableChildrenWhenDisabled" format="boolean" />
33343337
</declare-styleable>
33353338

33363339
<declare-styleable name="DatePicker">

core/res/res/values/styles.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,7 @@ please see styles_device_defaults.xml.
17981798
<item name="android:dropDownWidth">wrap_content</item>
17991799
<item name="android:popupPromptView">@android:layout/simple_dropdown_hint</item>
18001800
<item name="android:gravity">left|center_vertical</item>
1801+
<item name="android:disableChildrenWhenDisabled">true</item>
18011802
</style>
18021803

18031804
<style name="Widget.Holo.Spinner.DropDown">

0 commit comments

Comments
 (0)