Java Code Examples for android.widget.Spinner#setPadding()
The following examples show how to use
android.widget.Spinner#setPadding() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DropdownView.java From Dashchan with Apache License 2.0 | 6 votes |
public DropdownView(Context context, AttributeSet attrs) { super(context, attrs); spinner = new Spinner(context); spinner.setId(android.R.id.edit); spinner.setPadding(0, 0, 0, 0); addView(spinner, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); LayoutParams layoutParams = (LayoutParams) spinner.getLayoutParams(); if (C.API_LOLLIPOP) { layoutParams.gravity = Gravity.CENTER_VERTICAL; setBackgroundResource(ResourceUtils.getResourceId(context, android.R.attr.editTextBackground, 0)); setAddStatesFromChildren(true); } else { float density = ResourceUtils.obtainDensity(context); layoutParams.setMargins(0, (int) (4f * density), 0, (int) (4f * density)); } }
Example 2
Source File: ForceLocalePreference.java From geopaparazzi with GNU General Public License v3.0 | 5 votes |
@Override protected View onCreateDialogView() { LinearLayout mainLayout = new LinearLayout(context); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); mainLayout.setLayoutParams(layoutParams); mainLayout.setOrientation(LinearLayout.VERTICAL); mainLayout.setPadding(25, 25, 25, 25); localesSpinner = new Spinner(context); localesSpinner.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); localesSpinner.setPadding(15, 5, 15, 5); final String[] localesArray = context.getResources().getStringArray(R.array.locales); ArrayAdapter<String> adapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, localesArray); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); localesSpinner.setAdapter(adapter); final String currentLocale = LocaleUtils.getCurrentLocale(context); if (currentLocale != null) { for (int i = 0; i < localesArray.length; i++) { if (localesArray[i].equals(currentLocale.trim())) { localesSpinner.setSelection(i); break; } } } mainLayout.addView(localesSpinner); return mainLayout; }
Example 3
Source File: CertificateViewer.java From delion with Apache License 2.0 | 4 votes |
private void showCertificateChain(byte[][] derData) { for (int i = 0; i < derData.length; i++) { addCertificate(derData[i]); } ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_spinner_item, mTitles) { @Override public View getView(int position, View convertView, ViewGroup parent) { TextView view = (TextView) super.getView(position, convertView, parent); // Add extra padding on the end side to avoid overlapping the dropdown arrow. ApiCompatibilityUtils.setPaddingRelative(view, mPadding, mPadding, mPadding * 2, mPadding); return view; } }; arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); LinearLayout dialogContainer = new LinearLayout(mContext); dialogContainer.setOrientation(LinearLayout.VERTICAL); TextView title = new TextView(mContext); title.setText(R.string.certtitle); ApiCompatibilityUtils.setTextAlignment(title, View.TEXT_ALIGNMENT_VIEW_START); ApiCompatibilityUtils.setTextAppearance(title, android.R.style.TextAppearance_Large); title.setTypeface(title.getTypeface(), Typeface.BOLD); title.setPadding(mPadding, mPadding, mPadding, mPadding / 2); dialogContainer.addView(title); Spinner spinner = new Spinner(mContext); ApiCompatibilityUtils.setTextAlignment(spinner, View.TEXT_ALIGNMENT_VIEW_START); spinner.setAdapter(arrayAdapter); spinner.setOnItemSelectedListener(this); spinner.setDropDownWidth(ViewGroup.LayoutParams.MATCH_PARENT); // Remove padding so that dropdown has same width as the spinner. spinner.setPadding(0, 0, 0, 0); dialogContainer.addView(spinner); LinearLayout certContainer = new LinearLayout(mContext); certContainer.setOrientation(LinearLayout.VERTICAL); for (int i = 0; i < mViews.size(); ++i) { LinearLayout certificateView = mViews.get(i); if (i != 0) { certificateView.setVisibility(LinearLayout.GONE); } certContainer.addView(certificateView); } ScrollView scrollView = new ScrollView(mContext); scrollView.addView(certContainer); dialogContainer.addView(scrollView); showDialogForView(dialogContainer); }
Example 4
Source File: CertificateViewer.java From AndroidChromium with Apache License 2.0 | 4 votes |
private void showCertificateChain(byte[][] derData) { for (int i = 0; i < derData.length; i++) { addCertificate(derData[i]); } ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_spinner_item, mTitles) { @Override public View getView(int position, View convertView, ViewGroup parent) { TextView view = (TextView) super.getView(position, convertView, parent); // Add extra padding on the end side to avoid overlapping the dropdown arrow. ApiCompatibilityUtils.setPaddingRelative(view, mPadding, mPadding, mPadding * 2, mPadding); return view; } }; arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); LinearLayout dialogContainer = new LinearLayout(mContext); dialogContainer.setOrientation(LinearLayout.VERTICAL); TextView title = new TextView(mContext); title.setText(R.string.certtitle); ApiCompatibilityUtils.setTextAlignment(title, View.TEXT_ALIGNMENT_VIEW_START); ApiCompatibilityUtils.setTextAppearance(title, android.R.style.TextAppearance_Large); title.setTypeface(title.getTypeface(), Typeface.BOLD); title.setPadding(mPadding, mPadding, mPadding, mPadding / 2); dialogContainer.addView(title); Spinner spinner = new Spinner(mContext); ApiCompatibilityUtils.setTextAlignment(spinner, View.TEXT_ALIGNMENT_VIEW_START); spinner.setAdapter(arrayAdapter); spinner.setOnItemSelectedListener(this); spinner.setDropDownWidth(ViewGroup.LayoutParams.MATCH_PARENT); // Remove padding so that dropdown has same width as the spinner. spinner.setPadding(0, 0, 0, 0); dialogContainer.addView(spinner); LinearLayout certContainer = new LinearLayout(mContext); certContainer.setOrientation(LinearLayout.VERTICAL); for (int i = 0; i < mViews.size(); ++i) { LinearLayout certificateView = mViews.get(i); if (i != 0) { certificateView.setVisibility(LinearLayout.GONE); } certContainer.addView(certificateView); } ScrollView scrollView = new ScrollView(mContext); scrollView.addView(certContainer); dialogContainer.addView(scrollView); showDialogForView(dialogContainer); }
Example 5
Source File: LabelledSpinner.java From UsefulViews with Apache License 2.0 | 4 votes |
/** * Sets up views and widget attributes * * @param context Context passed from constructor * @param attrs AttributeSet passed from constructor */ private void initializeLayout(Context context, AttributeSet attrs) { prepareLayout(context); mLabel = (TextView) getChildAt(0); mSpinner = (Spinner) getChildAt(1); mDivider = getChildAt(2); mErrorLabel = (TextView) getChildAt(3); final TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.LabelledSpinner, 0, 0); String labelText = a.getString(R.styleable.LabelledSpinner_labelText); mWidgetColor = a.getColor(R.styleable.LabelledSpinner_widgetColor, ContextCompat.getColor(context, R.color.widget_labelled_spinner_default)); mLabel.setText(labelText); mLabel.setPadding(0, dpToPixels(16), 0, 0); mSpinner.setPadding(0, dpToPixels(8), 0, dpToPixels(8)); mSpinner.setOnItemSelectedListener(this); MarginLayoutParams dividerParams = (MarginLayoutParams) mDivider.getLayoutParams(); dividerParams.rightMargin = dpToPixels(4); dividerParams.bottomMargin = dpToPixels(8); mDivider.setLayoutParams(dividerParams); mLabel.setTextColor(mWidgetColor); mDivider.setBackgroundColor(mWidgetColor); alignLabelWithSpinnerItem(4); final CharSequence[] entries = a.getTextArray(R.styleable.LabelledSpinner_spinnerEntries); if (entries != null) { setItemsArray(entries); } mDefaultErrorEnabled = a.getBoolean(R.styleable.LabelledSpinner_defaultErrorEnabled, false); mDefaultErrorText = getResources().getString(R.string.widget_labelled_spinner_errorText); a.recycle(); }
Example 6
Source File: CertificateViewer.java From 365browser with Apache License 2.0 | 4 votes |
private void showCertificateChain(byte[][] derData) { for (int i = 0; i < derData.length; i++) { addCertificate(derData[i]); } ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_spinner_item, mTitles) { @Override public View getView(int position, View convertView, ViewGroup parent) { TextView view = (TextView) super.getView(position, convertView, parent); // Add extra padding on the end side to avoid overlapping the dropdown arrow. ApiCompatibilityUtils.setPaddingRelative(view, mPadding, mPadding, mPadding * 2, mPadding); return view; } }; arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); LinearLayout dialogContainer = new LinearLayout(mContext); dialogContainer.setOrientation(LinearLayout.VERTICAL); TextView title = new TextView(mContext); title.setText(R.string.certtitle); ApiCompatibilityUtils.setTextAlignment(title, View.TEXT_ALIGNMENT_VIEW_START); ApiCompatibilityUtils.setTextAppearance(title, android.R.style.TextAppearance_Large); title.setTypeface(title.getTypeface(), Typeface.BOLD); title.setPadding(mPadding, mPadding, mPadding, mPadding / 2); dialogContainer.addView(title); Spinner spinner = new Spinner(mContext); ApiCompatibilityUtils.setTextAlignment(spinner, View.TEXT_ALIGNMENT_VIEW_START); spinner.setAdapter(arrayAdapter); spinner.setOnItemSelectedListener(this); spinner.setDropDownWidth(ViewGroup.LayoutParams.MATCH_PARENT); // Remove padding so that dropdown has same width as the spinner. spinner.setPadding(0, 0, 0, 0); dialogContainer.addView(spinner); LinearLayout certContainer = new LinearLayout(mContext); certContainer.setOrientation(LinearLayout.VERTICAL); for (int i = 0; i < mViews.size(); ++i) { LinearLayout certificateView = mViews.get(i); if (i != 0) { certificateView.setVisibility(LinearLayout.GONE); } certContainer.addView(certificateView); } ScrollView scrollView = new ScrollView(mContext); scrollView.addView(certContainer); dialogContainer.addView(scrollView); showDialogForView(dialogContainer); }
Example 7
Source File: AddAccountActivity.java From YiBo with Apache License 2.0 | 4 votes |
private void initComponents() { LinearLayout llHeaderBase = (LinearLayout)findViewById(R.id.llHeaderBase); ScrollView svContentPanel = (ScrollView)findViewById(R.id.svContentPanel); spServiceProvider = (Spinner) findViewById(R.id.spServiceProvider); spConfigApp = (Spinner) findViewById(R.id.spConfigApp); etUsername = (EditText) findViewById(R.id.etUsername); etPassword = (EditText) findViewById(R.id.etPassword); cbMakeDefault = (CheckBox) findViewById(R.id.cbDefault); cbFollowOffical = (CheckBox) findViewById(R.id.cbFollowOffical); cbUseProxy = (CheckBox) findViewById(R.id.cbUseApiProxy); etRestProxy = (EditText) findViewById(R.id.etRestProxy); etSearchProxy = (EditText) findViewById(R.id.etSearchProxy); btnAuthorize = (Button) findViewById(R.id.btnAuthorize); LinearLayout llOAuthIntro = (LinearLayout)findViewById(R.id.llOAuthIntro); TextView tvOAuthIntro = (TextView)findViewById(R.id.tvOAuthIntro); LinearLayout llFooterAction = (LinearLayout)findViewById(R.id.llFooterAction); ThemeUtil.setSecondaryHeader(llHeaderBase); ThemeUtil.setContentBackground(svContentPanel); spServiceProvider.setBackgroundDrawable(theme.getDrawable("selector_btn_dropdown")); spConfigApp.setBackgroundDrawable(theme.getDrawable("selector_btn_dropdown")); int padding2 = theme.dip2px(2); spServiceProvider.setPadding(padding2, padding2, padding2, padding2); spConfigApp.setPadding(padding2, padding2, padding2, padding2); int content = theme.getColor("content"); etUsername.setBackgroundDrawable(theme.getDrawable("selector_input_frame")); etUsername.setTextColor(content); etPassword.setBackgroundDrawable(theme.getDrawable("selector_input_frame")); etPassword.setTextColor(content); cbMakeDefault.setButtonDrawable(theme.getDrawable("selector_checkbox")); cbMakeDefault.setTextColor(content); cbFollowOffical.setButtonDrawable(theme.getDrawable("selector_checkbox")); cbFollowOffical.setTextColor(content); cbUseProxy.setButtonDrawable(theme.getDrawable("selector_checkbox")); cbUseProxy.setTextColor(content); etRestProxy.setBackgroundDrawable(theme.getDrawable("selector_input_frame")); etRestProxy.setTextColor(content); etSearchProxy.setBackgroundDrawable(theme.getDrawable("selector_input_frame")); etSearchProxy.setTextColor(content); llOAuthIntro.setBackgroundDrawable(theme.getDrawable("bg_frame_normal")); int padding8 = theme.dip2px(8); llOAuthIntro.setPadding(padding8, padding8, padding8, padding8); tvOAuthIntro.setTextColor(theme.getColor("quote")); llFooterAction.setBackgroundDrawable(theme.getDrawable("bg_footer_action")); llFooterAction.setPadding(padding8, padding8, padding8, padding8); llFooterAction.setGravity(Gravity.CENTER); ThemeUtil.setBtnActionPositive(btnAuthorize); TextView tvTitle = (TextView) this.findViewById(R.id.tvTitle); tvTitle.setText(R.string.title_add_account); ConfigSystemDao configDao = new ConfigSystemDao(this); Passport passport = configDao.getPassport(); if (passport != null) { isCustomKeyLevel = passport.getPointsLevel().getPoints() >= Constants.POINTS_CUSTOM_SOURCE_LEVEL ; } isCustomKeyLevel = true; // 调试用 if (isCustomKeyLevel) { } }