Example usage for android.widget TextView setBackground

List of usage examples for android.widget TextView setBackground

Introduction

In this page you can find the example usage for android.widget TextView setBackground.

Prototype

public void setBackground(Drawable background) 

Source Link

Document

Set the background to a given Drawable, or remove the background.

Usage

From source file:com.coolerfall.uiart.PagerSlidingTabStrip.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void setBackgroundJelly(TextView tab) {
    tab.setBackground(createDrawable());
}

From source file:com.makotogo.mobile.hoursdroid.HoursDetailFragment.java

private void configureEndDate(View view) {
    TextView endDateTextView = (TextView) view.findViewById(R.id.textview_hours_detail_end_date);
    endDateTextView.setEnabled(isThisHoursRecordNotActive());
    if (isThisHoursRecordActive()) {
        endDateTextView.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.no_border, null));
    } else {/*www.  j a  v  a 2s . co m*/
        endDateTextView
                .setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.rounded_border, null));
    }
    endDateTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            FragmentManager fragmentManager = getFragmentManager();
            // If there is already a Date displayed, use that.
            Date dateToUse = (mHours.getEnd() == null) ? new Date() : mHours.getEnd();
            DateTimePickerFragment datePickerFragment = FragmentFactory.createDatePickerFragment(dateToUse,
                    "End", DateTimePickerFragment.BOTH);
            datePickerFragment.setTargetFragment(HoursDetailFragment.this, REQUEST_END_DATE_PICKER);
            datePickerFragment.show(fragmentManager, DateTimePickerFragment.DIALOG_TAG);
        }
    });
    if (mHours.getEnd() != null) {
        LocalDateTime endDateTime = new LocalDateTime(mHours.getEnd().getTime());
        endDateTextView.setText(endDateTime.toString(DATE_FORMAT_PATTERN));
    }
}

From source file:com.makotogo.mobile.hoursdroid.HoursDetailFragment.java

private void configureBreakTime(View view) {
    TextView breakTimeTextView = (TextView) view.findViewById(R.id.textview_hours_detail_break);
    breakTimeTextView.setEnabled(isThisHoursRecordNotActive());
    if (isThisHoursRecordActive()) {
        breakTimeTextView
                .setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.no_border, null));
    } else {/* w w  w  .  ja  v  a  2s . c  om*/
        breakTimeTextView
                .setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.rounded_border, null));
    }
    breakTimeTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            FragmentManager fragmentManager = getFragmentManager();
            Integer minutes = renderStorageBreakForEdit(mHours.getBreak().intValue());
            Log.d(TAG, "Number of minutes: " + minutes);
            // Max minutes can at most be number of minutes diff between end and begin
            Integer maxMinutes = (int) (mHours.getEnd().getTime() - mHours.getBegin().getTime()) / 60000;
            NumberPickerFragment numberPickerFragment = FragmentFactory.createNumberPickerFragment(minutes,
                    maxMinutes, "Break Time");
            numberPickerFragment.setTargetFragment(HoursDetailFragment.this, REQUEST_BREAK);
            numberPickerFragment.show(fragmentManager, NumberPickerFragment.DIALOG_TAG);
        }
    });
    breakTimeTextView.setText(renderTimePeriodForDisplay(mHours.getBreak()));
}

From source file:com.makotogo.mobile.hoursdroid.HoursDetailFragment.java

private void configureBeginDate(View view) {
    TextView beginDateTextView = (TextView) view.findViewById(R.id.textview_hours_detail_begin_date);
    beginDateTextView.setEnabled(isThisHoursRecordNotActive());
    if (isThisHoursRecordActive()) {
        beginDateTextView
                .setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.no_border, null));
    } else {//from  w w w  .  ja  va 2  s . co  m
        beginDateTextView
                .setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.rounded_border, null));
    }
    beginDateTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            FragmentManager fragmentManager = getFragmentManager();
            // If there is already a Date displayed, use that.
            Date dateToUse = (mHours.getBegin() == null) ? new Date() : mHours.getBegin();
            DateTimePickerFragment datePickerFragment = FragmentFactory.createDatePickerFragment(dateToUse,
                    "Begin", DateTimePickerFragment.BOTH);
            datePickerFragment.setTargetFragment(HoursDetailFragment.this, REQUEST_BEGIN_DATE_PICKER);
            datePickerFragment.show(fragmentManager, DateTimePickerFragment.DIALOG_TAG);
        }
    });
    if (mHours.getBegin() != null) {
        LocalDateTime beginDateTime = new LocalDateTime(mHours.getBegin().getTime());
        beginDateTextView.setText(beginDateTime.toString(DATE_FORMAT_PATTERN));
    }
}

From source file:de.kodejak.hashr.fragmentHashFromFile.java

public void OnButtonCompareClick() {
    TextView edOutput = (TextView) getView().findViewById(R.id.edOutput);
    String strOutput = edOutput.getText().toString();
    EditText edCompare = (EditText) getView().findViewById(R.id.edCompare);
    String strCompare = edCompare.getText().toString();
    TextView tvMatch = (TextView) getView().findViewById(R.id.tvCompare);

    if (strOutput.length() < 1 || strCompare.length() < 1) {
        return;//  w ww . j a  va2s . c  o  m
    }

    if (strOutput.equals(strCompare)) {
        tvMatch.setText("Match !");
        if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            tvMatch.setBackgroundDrawable(getResources().getDrawable(R.drawable.match_ok_bg));
        } else {
            tvMatch.setBackground(getResources().getDrawable(R.drawable.match_ok_bg));
        }
        tvMatch.setTextColor(Color.WHITE);
        tvMatch.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_check, 0, 0, 0);
    } else {
        tvMatch.setText("No match !");
        if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            tvMatch.setBackgroundDrawable(getResources().getDrawable(R.drawable.match_notok_bg));
        } else {
            tvMatch.setBackground(getResources().getDrawable(R.drawable.match_notok_bg));
        }
        tvMatch.setTextColor(Color.WHITE);
        tvMatch.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_cancel, 0, 0, 0);
    }

    tvMatch.setVisibility(View.VISIBLE);
}

From source file:com.github.akinaru.rfdroid.activity.BtDevicesActivity.java

public void altTableRow(int alt_row) {
    int childViewCount = tablelayout.getChildCount();

    for (int i = 0; i < childViewCount; i++) {
        TableRow row = (TableRow) tablelayout.getChildAt(i);

        for (int j = 0; j < row.getChildCount(); j++) {

            TextView tv = (TextView) row.getChildAt(j);
            if (i % alt_row != 0) {
                tv.setBackground(getResources().getDrawable(R.drawable.alt_row_color));
            } else {
                tv.setBackground(getResources().getDrawable(R.drawable.row_color));
            }//w  ww .  j  ava 2  s. c  om
        }
    }
}

From source file:net.yanzm.mth.MaterialTabHost.java

/**
 * add new tab with title text/*from   w  w w.ja  v a  2  s .com*/
 *
 * @param title title text
 */
public void addTab(CharSequence title) {
    int layoutId = getLayoutId(type);
    TextView tv = (TextView) inflater.inflate(layoutId, tabWidget, false);
    tv.setText(title);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        tv.setBackgroundResource(R.drawable.mth_tab_widget_background_ripple);

    } else {
        // create background using colorControlActivated
        StateListDrawable d = new StateListDrawable();
        d.addState(new int[] { android.R.attr.state_pressed }, new ColorDrawable(colorControlActivated));
        d.setAlpha(180);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            tv.setBackground(d);
        } else {
            tv.setBackgroundDrawable(d);
        }
    }

    int tabId = tabWidget.getTabCount();

    addTab(newTabSpec(String.valueOf(tabId)).setIndicator(tv).setContent(android.R.id.tabcontent));
}

From source file:ru.adios.budgeter.widgets.DataTableLayout.java

private void populateColumn(TextView view, Context context, float weight) {
    view.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
            TableRow.LayoutParams.WRAP_CONTENT, weight));
    view.setId(ElementsIdProvider.getNextId());
    view.setBackground(ContextCompat.getDrawable(context, R.drawable.cell_shape));
    final int fiveDp = getDpAsPixels(5, context);
    view.setPadding(fiveDp, fiveDp, fiveDp, fiveDp);
    view.setTextAppearance(context, android.R.style.TextAppearance_Small);
}

From source file:org.mozilla.focus.widget.TelemetrySwitchPreference.java

@Override
protected void onBindView(final View view) {
    super.onBindView(view);

    final Switch switchWidget = view.findViewById(R.id.switch_widget);

    switchWidget.setChecked(TelemetryWrapper.isTelemetryEnabled(getContext()));

    switchWidget.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override/*from  w w w.  j  a v a  2s.com*/
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            TelemetryWrapper.setTelemetryEnabled(getContext(), isChecked);
        }
    });

    final Resources resources = view.getResources();

    final TextView summary = view.findViewById(android.R.id.summary);
    summary.setText(resources.getString(R.string.preference_mozilla_telemetry_summary2,
            resources.getString(R.string.app_name)));

    final TextView learnMoreLink = view.findViewById(R.id.link);
    learnMoreLink.setPaintFlags(learnMoreLink.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    learnMoreLink.setTextColor(ContextCompat.getColor(view.getContext(), R.color.colorAction));
    learnMoreLink.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // This is a hardcoded link: if we ever end up needing more of these links, we should
            // move the link into an xml parameter, but there's no advantage to making it configurable now.
            final String url = SupportUtils.getSumoURLForTopic(getContext(), "usage-data");
            final String title = getTitle().toString();

            final Intent intent = InfoActivity.getIntentFor(getContext(), url, title);
            getContext().startActivity(intent);
        }
    });

    final TypedArray backgroundDrawableArray = view.getContext()
            .obtainStyledAttributes(new int[] { R.attr.selectableItemBackground });
    final Drawable backgroundDrawable = backgroundDrawableArray.getDrawable(0);
    backgroundDrawableArray.recycle();
    learnMoreLink.setBackground(backgroundDrawable);

    // We still want to allow toggling the pref by touching any part of the pref (except for
    // the "learn more" link)
    setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            switchWidget.toggle();
            return true;
        }
    });
}

From source file:com.tooltip.Tooltip.java

private View getContentView(Builder builder) {
    GradientDrawable drawable = new GradientDrawable();
    drawable.setColor(builder.mBackgroundColor);
    drawable.setCornerRadius(builder.mCornerRadius);

    int padding = (int) builder.mPadding;

    TextView textView = new TextView(builder.mContext);
    TextViewCompat.setTextAppearance(textView, builder.mTextAppearance);
    textView.setText(builder.mText);// w  w  w .j  a va  2 s  . co  m
    textView.setPadding(padding, padding, padding, padding);
    textView.setLineSpacing(builder.mLineSpacingExtra, builder.mLineSpacingMultiplier);
    textView.setTypeface(builder.mTypeface, builder.mTextStyle);

    if (builder.mTextSize >= 0) {
        textView.setTextSize(TypedValue.TYPE_NULL, builder.mTextSize);
    }
    if (builder.mTextColor != null) {
        textView.setTextColor(builder.mTextColor);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        textView.setBackground(drawable);
    } else {
        //noinspection deprecation
        textView.setBackgroundDrawable(drawable);
    }

    LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0);
    textViewParams.gravity = Gravity.CENTER;
    textView.setLayoutParams(textViewParams);

    mArrowView = new ImageView(builder.mContext);
    mArrowView.setImageDrawable(builder.mArrowDrawable);

    LinearLayout.LayoutParams arrowLayoutParams;
    if (mGravity == Gravity.TOP || mGravity == Gravity.BOTTOM) {
        arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowWidth, (int) builder.mArrowHeight,
                0);
    } else {
        arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowHeight, (int) builder.mArrowWidth,
                0);
    }
    arrowLayoutParams.gravity = Gravity.CENTER;
    mArrowView.setLayoutParams(arrowLayoutParams);

    mContentView = new LinearLayout(builder.mContext);
    mContentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    mContentView.setOrientation(mGravity == Gravity.START || mGravity == Gravity.END ? LinearLayout.HORIZONTAL
            : LinearLayout.VERTICAL);

    padding = (int) Util.dpToPx(5);

    switch (mGravity) {
    case Gravity.START:
        mContentView.setPadding(0, 0, padding, 0);
        break;
    case Gravity.TOP:
    case Gravity.BOTTOM:
        mContentView.setPadding(padding, 0, padding, 0);
        break;
    case Gravity.END:
        mContentView.setPadding(padding, 0, 0, 0);
        break;
    }

    if (mGravity == Gravity.TOP || mGravity == Gravity.START) {
        mContentView.addView(textView);
        mContentView.addView(mArrowView);
    } else {
        mContentView.addView(mArrowView);
        mContentView.addView(textView);
    }

    mContentView.setOnClickListener(mClickListener);
    mContentView.setOnLongClickListener(mLongClickListener);

    if (builder.isCancelable || builder.isDismissOnClick) {
        mContentView.setOnTouchListener(mTouchListener);
    }
    return mContentView;
}