MenuItem spinnerItem = menu.add(null); spinnerItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); IcsSpinner spinner = new IcsSpinner(this, null); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( this, R.array.items, R.layout.sherlock_spinner_item); adapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); spinnerItem.setActionView(spinner);
// actionDropDownStyle is an attribute set in the theme to e.g. @style/Widget.Sherlock.Spinner.DropDown.ActionBar or @style/Widget.Sherlock.Light.Spinner.DropDown.ActionBar for light theme IcsSpinner spinner = new IcsSpinner(context, null, R.attr.actionDropDownStyle); // yes here we set the offset! spinner.setVerticalOffsetBottom(offset); spinner.setPadding(spinner.getPaddingLeft(), 0, spinner.getPaddingRight(), 0); spinner.setId(R.id.some_id); spinner.setAdapter(yourAdapter); // you can use a simple ArrayAdapter or whatever you need // create ICS LinearLayout LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE ); IcsLinearLayout linearLayout = (IcsLinearLayout) inflater.inflate(R.layout.abs__action_bar_tab_bar_view, null); linearLayout .setPadding(listNavLayout.getPaddingLeft(), 0, listNavLayout.getPaddingRight(), 0); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); params.gravity = Gravity.CENTER; linearLayout .addView(spinner, params);
void layout(int delta, boolean animate) { int childrenLeft = mSpinnerPadding.left; int childrenWidth = getRight() - getLeft() - mSpinnerPadding.left - mSpinnerPadding.right; handleDataChanged(); resetList(); return; setSelectedPositionInt(mNextSelectedPosition); recycleAllViews(); removeAllViewsInLayout(); View sel = makeAndAddView(mSelectedPosition); int width = sel.getMeasuredWidth(); int selectedOffset = childrenLeft; invalidate(); checkSelectionChanged(); setNextSelectedPositionInt(mSelectedPosition);
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if (mPopup != null && MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.AT_MOST) { final int measuredWidth = getMeasuredWidth(); setMeasuredDimension(Math.min(Math.max(measuredWidth, measureContentWidth(getAdapter(), getBackground())), MeasureSpec.getSize(widthMeasureSpec)), getMeasuredHeight()); } }
private IcsSpinner createSpinner() { final IcsSpinner spinner = new IcsSpinner(getContext(), null, R.attr.actionDropDownStyle); spinner.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)); spinner.setOnItemSelectedListener(this); return spinner; }
@Override public void show() { final int spinnerPaddingLeft = IcsSpinner.this.getPaddingLeft(); if (mDropDownWidth == WRAP_CONTENT) { final int spinnerWidth = IcsSpinner.this.getWidth(); final int spinnerPaddingRight = IcsSpinner.this.getPaddingRight(); setContentWidth(Math.max( measureContentWidth((SpinnerAdapter) mAdapter, getBackground()), spinnerWidth - spinnerPaddingLeft - spinnerPaddingRight)); } else if (mDropDownWidth == MATCH_PARENT) { final int spinnerWidth = IcsSpinner.this.getWidth(); final int spinnerPaddingRight = IcsSpinner.this.getPaddingRight(); setContentWidth(spinnerWidth - spinnerPaddingLeft - spinnerPaddingRight); } 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); setSelection(IcsSpinner.this.getSelectedItemPosition()); } }
lp = generateDefaultLayoutParams(); addViewInLayout(child, 0, lp); child.setSelected(hasFocus()); if (mDisableChildrenWhenDisabled) { child.setEnabled(isEnabled()); + ((getMeasuredHeight() - mSpinnerPadding.bottom - mSpinnerPadding.top - child.getMeasuredHeight()) / 2); int childBottom = childTop + child.getMeasuredHeight();
case ActionBar.NAVIGATION_MODE_LIST: if (mSpinner == null) { mSpinner = new IcsSpinner(mContext, null, R.attr.actionDropDownStyle); mListNavLayout = (IcsLinearLayout) LayoutInflater.from(mContext) mListNavLayout.addView(mSpinner, params); if (mSpinner.getAdapter() != mSpinnerAdapter) { mSpinner.setAdapter(mSpinnerAdapter); mSpinner.setOnItemSelectedListener(mNavItemSelectedListener); addView(mListNavLayout); break;
private void performCollapse() { if (isCollapsed()) return; if (mTabSpinner == null) { mTabSpinner = createSpinner(); } removeView(mTabLayout); addView(mTabSpinner, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); if (mTabSpinner.getAdapter() == null) { mTabSpinner.setAdapter(new TabAdapter()); } if (mTabSelector != null) { removeCallbacks(mTabSelector); mTabSelector = null; } mTabSpinner.setSelection(mSelectedTabIndex); }
public void removeTabAt(int position) { mTabLayout.removeViewAt(position); if (mTabSpinner != null) { ((TabAdapter) mTabSpinner.getAdapter()).notifyDataSetChanged(); } if (mAllowCollapse) { requestLayout(); } }
public void setDropdownAdapter(SpinnerAdapter adapter) { mSpinnerAdapter = adapter; if (mSpinner != null) { mSpinner.setAdapter(adapter); } }
@Override public void show() { final int spinnerPaddingLeft = IcsSpinner.this.getPaddingLeft(); if (mDropDownWidth == WRAP_CONTENT) { final int spinnerWidth = IcsSpinner.this.getWidth(); final int spinnerPaddingRight = IcsSpinner.this.getPaddingRight(); setContentWidth(Math.max( measureContentWidth((SpinnerAdapter) mAdapter, getBackground()), spinnerWidth - spinnerPaddingLeft - spinnerPaddingRight)); } else if (mDropDownWidth == MATCH_PARENT) { final int spinnerWidth = IcsSpinner.this.getWidth(); final int spinnerPaddingRight = IcsSpinner.this.getPaddingRight(); setContentWidth(spinnerWidth - spinnerPaddingLeft - spinnerPaddingRight); } 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); setSelection(IcsSpinner.this.getSelectedItemPosition()); } }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if (mPopup != null && MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.AT_MOST) { final int measuredWidth = getMeasuredWidth(); setMeasuredDimension(Math.min(Math.max(measuredWidth, measureContentWidth(getAdapter(), getBackground())), MeasureSpec.getSize(widthMeasureSpec)), getMeasuredHeight()); } }
lp = generateDefaultLayoutParams(); addViewInLayout(child, 0, lp); child.setSelected(hasFocus()); if (mDisableChildrenWhenDisabled) { child.setEnabled(isEnabled()); + ((getMeasuredHeight() - mSpinnerPadding.bottom - mSpinnerPadding.top - child.getMeasuredHeight()) / 2); int childBottom = childTop + child.getMeasuredHeight();
case ActionBar.NAVIGATION_MODE_LIST: if (mSpinner == null) { mSpinner = new IcsSpinner(mContext, null, R.attr.actionDropDownStyle); mListNavLayout = (IcsLinearLayout) LayoutInflater.from(mContext) mListNavLayout.addView(mSpinner, params); if (mSpinner.getAdapter() != mSpinnerAdapter) { mSpinner.setAdapter(mSpinnerAdapter); mSpinner.setOnItemSelectedListener(mNavItemSelectedListener); addView(mListNavLayout); break;
private IcsSpinner createSpinner() { final IcsSpinner spinner = new IcsSpinner(getContext(), null, R.attr.actionDropDownStyle); spinner.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)); spinner.setOnItemSelectedListener(this); return spinner; }
private void performCollapse() { if (isCollapsed()) return; if (mTabSpinner == null) { mTabSpinner = createSpinner(); } removeView(mTabLayout); addView(mTabSpinner, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); if (mTabSpinner.getAdapter() == null) { mTabSpinner.setAdapter(new TabAdapter()); } if (mTabSelector != null) { removeCallbacks(mTabSelector); mTabSelector = null; } mTabSpinner.setSelection(mSelectedTabIndex); }
public void removeAllTabs() { mTabLayout.removeAllViews(); if (mTabSpinner != null) { ((TabAdapter) mTabSpinner.getAdapter()).notifyDataSetChanged(); } if (mAllowCollapse) { requestLayout(); } }
public void setDropdownAdapter(SpinnerAdapter adapter) { mSpinnerAdapter = adapter; if (mSpinner != null) { mSpinner.setAdapter(adapter); } }
void layout(int delta, boolean animate) { int childrenLeft = mSpinnerPadding.left; int childrenWidth = getRight() - getLeft() - mSpinnerPadding.left - mSpinnerPadding.right; handleDataChanged(); resetList(); return; setSelectedPositionInt(mNextSelectedPosition); recycleAllViews(); removeAllViewsInLayout(); View sel = makeAndAddView(mSelectedPosition); int width = sel.getMeasuredWidth(); int selectedOffset = childrenLeft; invalidate(); checkSelectionChanged(); setNextSelectedPositionInt(mSelectedPosition);