Java Code Examples for android.widget.TextView#setEnabled()
The following examples show how to use
android.widget.TextView#setEnabled() .
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: PermissionStepLayout.java From ResearchStack with Apache License 2.0 | 6 votes |
private void updatePermissionItems() { List<PermissionRequestManager.PermissionRequest> items = PermissionRequestManager.getInstance() .getPermissionRequests(); for (PermissionRequestManager.PermissionRequest item : items) { boolean isGranted = PermissionRequestManager.getInstance().hasPermission(getContext(), item.getId()); View parent = findViewWithTag(item.getId()); TextView action = (TextView) parent.findViewById(R.id.permission_button); action.setText(isGranted ? R.string.rss_granted : item.isBlockingPermission() ? R.string.rss_allow : R.string.rss_optional); action.setEnabled(!isGranted); } }
Example 2
Source File: OptionalGridViewAdapter.java From BaoKanAndroid with MIT License | 6 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { View view = LayoutInflater.from(context).inflate(R.layout.item_column_item, null); item_text = (TextView) view.findViewById(R.id.text_item); String className = getItem(position).getClassname(); item_text.setText(className); if (isSelected) { if ((position == 0) || (position == 1)) { item_text.setEnabled(false); } } if (!isVisible && (position == -1 + optionalList.size())) { item_text.setText(""); item_text.setSelected(true); item_text.setEnabled(true); } if (remove_position == position) { item_text.setText(""); } return view; }
Example 3
Source File: PlayActivity.java From FixMath with Apache License 2.0 | 6 votes |
void blockGoodAnswerFigures(String figureType){ for (int i = Up; i <= Down; i++) { for (int x = 0; x <= 4; x++) { String TextViewId = "var" + i + "x" + x; int id = getResources().getIdentifier(TextViewId, "id", getPackageName()); TextView allTextContainer = (TextView) findViewById(id); if(allTextContainer.getTag() != null) { String containerTags = allTextContainer.getTag().toString(); if (containerTags.equals(figureType)) { SetFiguresColor(allTextContainer, figureType); allTextContainer.setEnabled(false); } } } } }
Example 4
Source File: FormTimeFieldCell.java From QMBForm with MIT License | 6 votes |
@Override protected void updateDateLabel(Date date, boolean disabled) { DateFormat dateFormat = android.text.format.DateFormat.getTimeFormat(getContext()); String s = dateFormat.format(date); TextView editView = getDetailTextView(); editView.setText(s); if (disabled) { editView.setEnabled(false); setTextColor(editView, CellDescriptor.COLOR_VALUE_DISABLED); } }
Example 5
Source File: FormButtonFieldCell.java From QMBForm with MIT License | 6 votes |
@Override protected void update() { super.update(); TextView textView = getTextView(); setStyleId(getTextView(), CellDescriptor.APPEARANCE_BUTTON, CellDescriptor.COLOR_VALUE); if (getRowDescriptor().getDisabled()) { setTextColor(textView, CellDescriptor.COLOR_VALUE_DISABLED); textView.setClickable(false); textView.setEnabled(false); setClickable(false); setEnabled(false); } }
Example 6
Source File: RxTool.java From RxTools-master with Apache License 2.0 | 6 votes |
/** * 倒计时 * * @param textView 控件 * @param waitTime 倒计时总时长 * @param interval 倒计时的间隔时间 * @param hint 倒计时完毕时显示的文字 */ public static void countDown(final TextView textView, long waitTime, long interval, final String hint) { textView.setEnabled(false); android.os.CountDownTimer timer = new android.os.CountDownTimer(waitTime, interval) { @Override public void onTick(long millisUntilFinished) { textView.setText("剩下 " + (millisUntilFinished / 1000) + " S"); } @Override public void onFinish() { textView.setEnabled(true); textView.setText(hint); } }; timer.start(); }
Example 7
Source File: OptionalGridViewAdapter.java From LiuAGeAndroid with MIT License | 6 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { View view = LayoutInflater.from(context).inflate(R.layout.item_column_item, null); item_text = (TextView) view.findViewById(R.id.text_item); String className = getItem(position).getClassname(); item_text.setText(className); if (isSelected) { if (position == 0) { item_text.setEnabled(false); } } if (!isVisible && (position == -1 + optionalList.size())) { item_text.setText(""); item_text.setSelected(true); item_text.setEnabled(true); } if (remove_position == position) { item_text.setText(""); } return view; }
Example 8
Source File: MyFragment.java From BehaviorCollect with GNU General Public License v3.0 | 5 votes |
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mTvLogin = (TextView) getView().findViewById(R.id.login_btn); mTvLogin.setEnabled(false);//登录的按钮默认置灰。 mTvLogin.setOnClickListener(this); }
Example 9
Source File: LoginFragment.java From BehaviorCollect with GNU General Public License v3.0 | 5 votes |
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mTvLogin = (TextView) getView().findViewById(R.id.login_btn); mTvLogin.setEnabled(false);//登录的按钮默认置灰。 mTvLogin.setOnClickListener(this); }
Example 10
Source File: MediaShowActivity.java From BigApp_WordPress_Android with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.zg_activity_media_show); mTV_catalog_name = (TextView) findViewById(R.id.tv_catalog_name); mTV_catalog_name.setOnClickListener(this); mTV_catalog_name.setEnabled(false); mTV_preview = (TextView) findViewById(R.id.tv_preview); mTV_preview.setOnClickListener(this); mTv_right = (TextView) findViewById(R.id.tv_right); mTv_right.setOnClickListener(this); findViewById(R.id.iv_left).setOnClickListener(this); initMode(); mImageLoader = ImageLoader.getInstance(); mGridView = (GridView) findViewById(R.id.gridview); mGridView.setFastScrollEnabled(true); PauseOnScrollListener listener = new PauseOnScrollListener( mImageLoader, true, true); mGridView.setOnScrollListener(listener); mMediaAdapter = new AdapterMediaShow(this, mediaType, mSelectedList); mGridView.setAdapter(mMediaAdapter); mGridView.setOnItemClickListener(this); new Thread(new getMediaInfoTask(null)).start(); }
Example 11
Source File: SuggestionStripLayoutHelper.java From openboard with GNU General Public License v3.0 | 5 votes |
/** * Format appropriately the suggested word in {@link #mWordViews} specified by * <code>positionInStrip</code>. When the suggested word doesn't exist, the corresponding * {@link TextView} will be disabled and never respond to user interaction. The suggested word * may be shrunk or ellipsized to fit in the specified width. * * The <code>positionInStrip</code> argument is the index in the suggestion strip. The indices * increase towards the right for LTR scripts and the left for RTL scripts, starting with 0. * The position of the most important suggestion is in {@link #mCenterPositionInStrip}. This * usually doesn't match the index in <code>suggedtedWords</code> -- see * {@link #getPositionInSuggestionStrip(int,SuggestedWords)}. * * @param positionInStrip the position in the suggestion strip. * @param width the maximum width for layout in pixels. * @return the {@link TextView} containing the suggested word appropriately formatted. */ private TextView layoutWord(final Context context, final int positionInStrip, final int width) { final TextView wordView = mWordViews.get(positionInStrip); final CharSequence word = wordView.getText(); if (positionInStrip == mCenterPositionInStrip && mMoreSuggestionsAvailable) { // TODO: This "more suggestions hint" should have a nicely designed icon. wordView.setCompoundDrawablesWithIntrinsicBounds( null, null, null, mMoreSuggestionsHint); // HACK: Align with other TextViews that have no compound drawables. wordView.setCompoundDrawablePadding(-mMoreSuggestionsHint.getIntrinsicHeight()); } else { wordView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); } // {@link StyleSpan} in a content description may cause an issue of TTS/TalkBack. // Use a simple {@link String} to avoid the issue. wordView.setContentDescription( TextUtils.isEmpty(word) ? context.getResources().getString(R.string.spoken_empty_suggestion) : word.toString()); final CharSequence text = getEllipsizedTextWithSettingScaleX( word, width, wordView.getPaint()); final float scaleX = wordView.getTextScaleX(); wordView.setText(text); // TextView.setText() resets text scale x to 1.0. wordView.setTextScaleX(scaleX); // A <code>wordView</code> should be disabled when <code>word</code> is empty in order to // make it unclickable. // With accessibility touch exploration on, <code>wordView</code> should be enabled even // when it is empty to avoid announcing as "disabled". wordView.setEnabled(!TextUtils.isEmpty(word) || AccessibilityUtils.Companion.getInstance().isTouchExplorationEnabled()); return wordView; }
Example 12
Source File: SearchActivity.java From Hentoid with Apache License 2.0 | 5 votes |
/** * Update the text of a given attribute type button based on the given SparseIntArray and relevant type(s) * * @param button Button whose text to update * @param attrCount Entry count in every attribute type (key = attribute type code; value = count) * @param types Type(s) to fetch the count for */ private void updateAttributeTypeButton(@NonNull final TextView button, @NonNull final SparseIntArray attrCount, AttributeType... types) { if (0 == types.length) return; int count = 0; for (AttributeType type : types) count += attrCount.get(type.getCode(), 0); button.setText(format("%s (%s)", Helper.capitalizeString(types[0].getDisplayName()), count)); button.setEnabled(count > 0); }
Example 13
Source File: SuggestionStripLayoutHelper.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 5 votes |
/** * Format appropriately the suggested word in {@link #mWordViews} specified by * <code>positionInStrip</code>. When the suggested word doesn't exist, the corresponding * {@link TextView} will be disabled and never respond to user interaction. The suggested word * may be shrunk or ellipsized to fit in the specified width. * * The <code>positionInStrip</code> argument is the index in the suggestion strip. The indices * increase towards the right for LTR scripts and the left for RTL scripts, starting with 0. * The position of the most important suggestion is in {@link #mCenterPositionInStrip}. This * usually doesn't match the index in <code>suggedtedWords</code> -- see * {@link #getPositionInSuggestionStrip(int,SuggestedWords)}. * * @param positionInStrip the position in the suggestion strip. * @param width the maximum width for layout in pixels. * @return the {@link TextView} containing the suggested word appropriately formatted. */ private TextView layoutWord(final Context context, final int positionInStrip, final int width) { final TextView wordView = mWordViews.get(positionInStrip); final CharSequence word = wordView.getText(); if (positionInStrip == mCenterPositionInStrip && mMoreSuggestionsAvailable) { // TODO: This "more suggestions hint" should have a nicely designed icon. wordView.setCompoundDrawablesWithIntrinsicBounds( null, null, null, mMoreSuggestionsHint); // HACK: Align with other TextViews that have no compound drawables. wordView.setCompoundDrawablePadding(-mMoreSuggestionsHint.getIntrinsicHeight()); } else { wordView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); } // {@link StyleSpan} in a content description may cause an issue of TTS/TalkBack. // Use a simple {@link String} to avoid the issue. wordView.setContentDescription( TextUtils.isEmpty(word) ? context.getResources().getString(R.string.spoken_empty_suggestion) : word.toString()); final CharSequence text = getEllipsizedTextWithSettingScaleX( word, width, wordView.getPaint()); final float scaleX = wordView.getTextScaleX(); wordView.setText(text); // TextView.setText() resets text scale x to 1.0. wordView.setTextScaleX(scaleX); // A <code>wordView</code> should be disabled when <code>word</code> is empty in order to // make it unclickable. // With accessibility touch exploration on, <code>wordView</code> should be enabled even // when it is empty to avoid announcing as "disabled". wordView.setEnabled(!TextUtils.isEmpty(word) || AccessibilityUtils.getInstance().isTouchExplorationEnabled()); return wordView; }
Example 14
Source File: DragGridViewAdapter.java From BaoKanAndroid with MIT License | 5 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { View view = LayoutInflater.from(context).inflate(R.layout.item_column_item, null); item_text = (TextView) view.findViewById(R.id.text_item); String className = getItem(position).getClassname(); item_text.setText(className); if (isUser) { if ((position == 0) || (position == 1)) { item_text.setEnabled(false); } } if (isChanged && (position == holdPosition) && !isItemShow) { item_text.setText(""); item_text.setSelected(true); item_text.setEnabled(true); isChanged = false; } if (!isVisible && (position == -1 + selectedList.size())) { item_text.setText(""); item_text.setSelected(true); item_text.setEnabled(true); } if (remove_position == position) { item_text.setText(""); } return view; }
Example 15
Source File: PaymentRequestSection.java From delion with Apache License 2.0 | 4 votes |
private TextView createLabel( GridLayout parent, int rowIndex, boolean iconExists, boolean isEnabled) { Context context = parent.getContext(); Resources resources = context.getResources(); // By default, the label appears to the right of the "button" in the second column. // + If there is no button and no icon, the label spans the whole row. // + If there is no icon, the label spans two columns. // + Otherwise, the label occupies only its own column. int columnStart = 1; int columnSpan = iconExists ? 1 : 2; TextView labelView = new TextView(context); if (mRowType == OPTION_ROW_TYPE_OPTION) { // Show the string representing the PaymentOption. ApiCompatibilityUtils.setTextAppearance(labelView, isEnabled ? R.style.PaymentsUiSectionDefaultText : R.style.PaymentsUiSectionDisabledText); labelView.setText(convertOptionToString(mOption)); labelView.setEnabled(isEnabled); } else if (mRowType == OPTION_ROW_TYPE_ADD) { // Shows string saying that the user can add a new option, e.g. credit card no. String typeface = resources.getString(R.string.roboto_medium_typeface); int textStyle = resources.getInteger(R.integer.roboto_medium_textstyle); int buttonHeight = resources.getDimensionPixelSize( R.dimen.payments_section_add_button_height); ApiCompatibilityUtils.setTextAppearance( labelView, R.style.PaymentsUiSectionAddButtonLabel); labelView.setMinimumHeight(buttonHeight); labelView.setGravity(Gravity.CENTER_VERTICAL); labelView.setTypeface(Typeface.create(typeface, textStyle)); } else if (mRowType == OPTION_ROW_TYPE_DESCRIPTION) { // The description spans all the columns. columnStart = 0; columnSpan = 3; ApiCompatibilityUtils.setTextAppearance( labelView, R.style.PaymentsUiSectionDescriptiveText); } else if (mRowType == OPTION_ROW_TYPE_WARNING) { // Warnings use two columns. columnSpan = 2; ApiCompatibilityUtils.setTextAppearance( labelView, R.style.PaymentsUiSectionWarningText); } // The label spans two columns if no icon exists. Setting the view width to 0 // forces it to stretch. GridLayout.LayoutParams labelParams = new GridLayout.LayoutParams( GridLayout.spec(rowIndex, 1, GridLayout.CENTER), GridLayout.spec(columnStart, columnSpan, GridLayout.FILL)); labelParams.topMargin = mVerticalMargin; labelParams.width = 0; parent.addView(labelView, labelParams); labelView.setOnClickListener(OptionSection.this); return labelView; }
Example 16
Source File: BootstrapDropDown.java From Android-Bootstrap with MIT License | 4 votes |
private ScrollView createDropDownView() { final LinearLayout dropdownView = new LinearLayout(getContext()); ScrollView scrollView = new ScrollView(getContext()); int clickableChildCounter = 0; dropdownView.setOrientation(LinearLayout.VERTICAL); int height = (int) (itemHeight * bootstrapSize); LayoutParams childParams = new LayoutParams(LayoutParams.MATCH_PARENT, height); for (String text : dropdownData) { TextView childView = new TextView(getContext()); childView.setGravity(Gravity.CENTER_VERTICAL); childView.setLayoutParams(childParams); int padding = (int) (baselineItemLeftPadding * bootstrapSize); childView.setPadding(padding, 0, padding, 0); childView.setTextSize(baselineDropDownViewFontSize * bootstrapSize); childView.setTextColor(ColorUtils.resolveColor(android.R.color.black, getContext())); Drawable background = getContext().obtainStyledAttributes(null, new int[]{ android.R.attr.selectableItemBackground}, 0, 0) .getDrawable(0); ViewUtils.setBackgroundDrawable(childView, background); childView.setTextColor(BootstrapDrawableFactory.bootstrapDropDownViewText(getContext())); childView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dropdownWindow.dismiss(); if (onDropDownItemClickListener != null) { onDropDownItemClickListener.onItemClick(dropdownView, v, v.getId()); } } }); if (Pattern.matches(SEARCH_REGEX_HEADER, text)) { childView.setText(text.replaceFirst(REPLACE_REGEX_HEADER, "")); childView.setTextSize((baselineDropDownViewFontSize - 2F) * bootstrapSize); childView.setClickable(false); childView.setTextColor(ColorUtils.resolveColor(R.color.bootstrap_gray_light, getContext())); } else if (Pattern.matches(SEARCH_REGEX_SEPARATOR, text)) { childView = new DividerView(getContext()); childView.setClickable(false); childView.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 3)); } else if (Pattern.matches(SEARCH_REGEX_DISABLED, text)) { childView.setEnabled(false); childView.setId(clickableChildCounter++); childView.setText(text.replaceFirst(REPLACE_REGEX_DISABLED, "")); } else { childView.setText(text); childView.setId(clickableChildCounter++); } dropdownView.addView(childView); } dropdownView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); dropDownViewHeight = dropdownView.getMeasuredHeight(); dropDownViewWidth = dropdownView.getMeasuredWidth(); scrollView.setVerticalScrollBarEnabled(false); scrollView.setHorizontalScrollBarEnabled(false); scrollView.addView(dropdownView); cleanData(); return scrollView; }
Example 17
Source File: LivePlayerController.java From letv with Apache License 2.0 | 4 votes |
private void setBtnLevelStatus(int num) { boolean z; boolean z2 = true; this.mBtnLevelSmooth.setSelected(num == 0); TextView textView = this.mBtnLevelSmooth; if (num != 0) { z = true; } else { z = false; } textView.setEnabled(z); textView = this.mBtnLevelStandard; if (num == 1) { z = true; } else { z = false; } textView.setSelected(z); textView = this.mBtnLevelStandard; if (num != 1) { z = true; } else { z = false; } textView.setEnabled(z); textView = this.mBtnLevelHigh; if (num == 2) { z = true; } else { z = false; } textView.setSelected(z); textView = this.mBtnLevelHigh; if (num != 2) { z = true; } else { z = false; } textView.setEnabled(z); textView = this.mBtnLevelSuper; if (num == 3) { z = true; } else { z = false; } textView.setSelected(z); textView = this.mBtnLevelSuper; if (num != 3) { z = true; } else { z = false; } textView.setEnabled(z); textView = this.mBtnLevel2K; if (num == 4) { z = true; } else { z = false; } textView.setSelected(z); textView = this.mBtnLevel2K; if (num != 4) { z = true; } else { z = false; } textView.setEnabled(z); textView = this.mBtnLevel4K; if (num == 5) { z = true; } else { z = false; } textView.setSelected(z); TextView textView2 = this.mBtnLevel4K; if (num == 5) { z2 = false; } textView2.setEnabled(z2); this.mCurrentSelectLevelPos = num; }
Example 18
Source File: SnackbarManager.java From pandroid with Apache License 2.0 | 4 votes |
private ToastNotifier makeCustomNotification(Activity activity, ToastType toastType, String label, String btnLabel, int drawableRes, int style, int duration, boolean undefinedLoad, final ToastListener listener) { if (duration < 0) duration = Snackbar.LENGTH_INDEFINITE; final Snackbar notif = Snackbar.make(activity.findViewById(android.R.id.content), label, duration); if (style == 0) { style = R.style.Toast; } TypedArray attributes = activity.obtainStyledAttributes(style, R.styleable.ToastAppearance); int textColor = attributes.getColor(R.styleable.ToastAppearance_toastTextColor, ContextCompat.getColor(activity, R.color.white)); int buttonTextColor = attributes.getColor(R.styleable.ToastAppearance_toastButtonTextColor, ContextCompat.getColor(activity, R.color.pandroid_green_dark)); int backgroundColor = attributes.getColor(R.styleable.ToastAppearance_toastBackground, ContextCompat.getColor(activity, R.color.pandroid_green)); notif.getView().setBackgroundColor(backgroundColor); ((TextView) notif.getView().findViewById(android.support.design.R.id.snackbar_text)).setTextColor(textColor); TextView actionView = ((TextView) notif.getView().findViewById(android.support.design.R.id.snackbar_action)); actionView.setTextColor(buttonTextColor); attributes.recycle(); notif.setCallback(new Snackbar.Callback() { @Override public void onDismissed(Snackbar snackbar, int event) { super.onDismissed(snackbar, event); if (listener != null) listener.onDismiss(); } }); Drawable drawable = null; if (drawableRes > 0) { drawable = ContextCompat.getDrawable(activity, drawableRes); } actionView.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, drawable, null); if (toastType == ToastType.ACTION && btnLabel != null) { notif.setAction(btnLabel, new View.OnClickListener() { @Override public void onClick(View view) { if (listener != null) listener.onActionClicked(); } }); } else if (drawableRes > 0) { actionView.setVisibility(View.VISIBLE); actionView.setClickable(false); actionView.setFocusableInTouchMode(false); actionView.setFocusable(false); actionView.setEnabled(false); } if (toastType == ToastType.LOADER) { ProgressWheel progressWheel = new ProgressWheel(activity); progressWheel.setId(R.id.snakebar_loader); if (undefinedLoad) progressWheel.spin(); progressWheel.setBarWidth((int) DeviceUtils.dpToPx(activity, 4)); progressWheel.setCircleRadius((int) DeviceUtils.dpToPx(activity, 30)); progressWheel.setBarColor(buttonTextColor); progressWheel.setLinearProgress(true); ((Snackbar.SnackbarLayout) notif.getView()).addView(progressWheel, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); } notif.show(); lastShowNotif = notif; return new ToastNotifier() { @Override public void setProgress(int progress) { ProgressWheel loader = (ProgressWheel) notif.getView().findViewById(R.id.snakebar_loader); if (loader != null) { loader.setProgress(progress / 100f); } } @Override public void dismiss() { notif.dismiss(); } }; }
Example 19
Source File: PlaceAndPhotoTestActivity.java From android-places-demos with Apache License 2.0 | 4 votes |
private void setEnabled(@IdRes int resId, boolean enabled) { TextView view = findViewById(resId); view.setEnabled(enabled); view.setText(""); }
Example 20
Source File: PaymentRequestSection.java From AndroidChromium with Apache License 2.0 | 4 votes |
private TextView createLabel(GridLayout parent, int rowIndex, boolean optionIconExists, boolean editIconExists, boolean isEnabled) { Context context = parent.getContext(); Resources resources = context.getResources(); // By default, the label appears to the right of the "button" in the second column. // + If there is no button, no option and edit icon, the label spans the whole row. // + If there is no option and edit icon, the label spans three columns. // + If there is no edit icon or option icon, the label spans two columns. // + Otherwise, the label occupies only its own column. int columnStart = 1; int columnSpan = 1; if (!optionIconExists) columnSpan++; if (!editIconExists) columnSpan++; TextView labelView = new TextView(context); if (mRowType == OPTION_ROW_TYPE_OPTION) { // Show the string representing the PaymentOption. ApiCompatibilityUtils.setTextAppearance(labelView, isEnabled ? R.style.PaymentsUiSectionDefaultText : R.style.PaymentsUiSectionDisabledText); labelView.setText(convertOptionToString( mOption, mDelegate.isBoldLabelNeeded(OptionSection.this))); labelView.setEnabled(isEnabled); } else if (mRowType == OPTION_ROW_TYPE_ADD) { // Shows string saying that the user can add a new option, e.g. credit card no. String typeface = resources.getString(R.string.roboto_medium_typeface); int textStyle = resources.getInteger(R.integer.roboto_medium_textstyle); int buttonHeight = resources.getDimensionPixelSize( R.dimen.payments_section_add_button_height); ApiCompatibilityUtils.setTextAppearance( labelView, R.style.PaymentsUiSectionAddButtonLabel); labelView.setMinimumHeight(buttonHeight); labelView.setGravity(Gravity.CENTER_VERTICAL); labelView.setTypeface(Typeface.create(typeface, textStyle)); } else if (mRowType == OPTION_ROW_TYPE_DESCRIPTION) { // The description spans all the columns. columnStart = 0; columnSpan = 4; ApiCompatibilityUtils.setTextAppearance( labelView, R.style.PaymentsUiSectionDescriptiveText); } else if (mRowType == OPTION_ROW_TYPE_WARNING) { // Warnings use three columns. columnSpan = 3; ApiCompatibilityUtils.setTextAppearance( labelView, R.style.PaymentsUiSectionWarningText); } // The label spans two columns if no option or edit icon, or spans three columns if // no option and edit icons. Setting the view width to 0 forces it to stretch. GridLayout.LayoutParams labelParams = new GridLayout.LayoutParams( GridLayout.spec(rowIndex, 1, GridLayout.CENTER), GridLayout.spec(columnStart, columnSpan, GridLayout.FILL)); labelParams.topMargin = mVerticalMargin; labelParams.width = 0; if (optionIconExists) { // Margin at the end of the label instead of the start of the option icon to // allow option icon in the the next row align with the end of label (include // end margin) when edit icon exits in that row, like below: // ---Label---------------------[label margin]|---option icon---| // ---Label---[label margin]|---option icon---|----edit icon----| ApiCompatibilityUtils.setMarginEnd(labelParams, mLargeSpacing); } parent.addView(labelView, labelParams); labelView.setOnClickListener(OptionSection.this); return labelView; }