Skip to content
This repository has been archived by the owner on Apr 19, 2018. It is now read-only.

Fix setting dropDownSelector and dropDownHorizontalOffset to IcsSpinner from custom style #625

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ public ListView getListView() {
return mDropDownList;
}

public void setDropdownSelector(Drawable selector) {
mDropDownListHighlight = selector;
}

private int buildDropDown() {
ViewGroup dropDownView;
int otherHeights = 0;
Expand Down
25 changes: 18 additions & 7 deletions library/src/com/actionbarsherlock/internal/widget/IcsSpinner.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ public IcsSpinner(Context context, AttributeSet attrs, int defStyle) {
popup.setHorizontalOffset(horizontalOffset);
}

popup.setDropdownSelector(a.getDrawable(
R.styleable.SherlockSpinner_android_dropDownSelector));

mPopup = popup;

mGravity = a.getInt(R.styleable.SherlockSpinner_android_gravity, Gravity.CENTER);
Expand Down Expand Up @@ -640,6 +643,7 @@ public void onClick(DialogInterface dialog, int which) {
private class DropdownPopup extends IcsListPopupWindow implements SpinnerPopup {
private CharSequence mHintText;
private ListAdapter mAdapter;
private int mHorizontalOffset;

public DropdownPopup(Context context, AttributeSet attrs, int defStyleRes) {
super(context, attrs, 0, defStyleRes);
Expand All @@ -654,6 +658,15 @@ public void onItemClick(AdapterView parent, View v, int position, long id) {
dismiss();
}
});

final Drawable background = getBackground();
int bgOffset = 0;
if (background != null) {
background.getPadding(mTempRect);
bgOffset = -mTempRect.left;
}
mHorizontalOffset = bgOffset + IcsSpinner.this.getPaddingLeft();
super.setHorizontalOffset(mHorizontalOffset);
}

@Override
Expand All @@ -671,6 +684,11 @@ public void setPromptText(CharSequence hintText) {
mHintText = hintText;
}

@Override
public void setHorizontalOffset(int offset) {
super.setHorizontalOffset(mHorizontalOffset + offset);
}

@Override
public void show() {
final int spinnerPaddingLeft = IcsSpinner.this.getPaddingLeft();
Expand All @@ -687,13 +705,6 @@ public void show() {
} else {
setContentWidth(mDropDownWidth);
}
final Drawable background = getBackground();
int bgOffset = 0;
if (background != null) {
background.getPadding(mTempRect);
bgOffset = -mTempRect.left;
}
setHorizontalOffset(bgOffset + spinnerPaddingLeft);
setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
super.show();
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
Expand Down