List of usage examples for android.widget TextView setBackground
public void setBackground(Drawable background)
From source file:com.ruesga.rview.misc.Formatter.java
@BindingAdapter({ "draftAccountDisplayName", "isDraft" }) public static void toDraftAccountDisplayName(TextView view, AccountInfo accountInfo, boolean isDraft) { if (isDraft) { Context ctx = view.getContext(); view.setText(ctx.getString(R.string.menu_draft).toUpperCase(AndroidHelper.getCurrentLocale(ctx))); Drawable dw = ContextCompat.getDrawable(ctx, R.drawable.bg_tag); DrawableCompat.setTint(dw, ContextCompat.getColor(ctx, R.color.unscored)); view.setBackground(dw); return;/*from ww w . ja v a 2 s . co m*/ } view.setBackground(null); toAccountDisplayName(view, accountInfo); }
From source file:com.example.android.leanback.StringPresenter.java
@Override public ViewHolder onCreateViewHolder(ViewGroup parent) { Log.d(TAG, "onCreateViewHolder"); final Context context = parent.getContext(); TextView tv = new TextView(context); tv.setFocusable(true);/*from ww w . j a va2s .c o m*/ tv.setFocusableInTouchMode(true); tv.setBackground( ResourcesCompat.getDrawable(context.getResources(), R.drawable.text_bg, context.getTheme())); return new ViewHolder(tv); }
From source file:com.github.akinaru.hcidebugger.activity.DescriptionActivity.java
/** * alternate between 2 colors for the description item table * * @param alt_row//from ww w . j a v a2s . c o m */ 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)); } } } }
From source file:cc.metapro.openct.customviews.DuringDialog.java
private void setViews(GridLayout gridLayout) { for (int i = 0; i < 5; i++) { for (int j = 0; j < 6; j++) { final int week = i * 6 + j + 1; final TextView textView = new TextView(getActivity()); textView.setText(week + gridLayout.getContext().getString(R.string.week)); textView.setGravity(Gravity.CENTER); if (DURING[week]) { textView.setBackground( ContextCompat.getDrawable(getActivity(), R.drawable.text_view_card_style_blue)); textView.setTextColor(ContextCompat.getColor(getActivity(), R.color.colorAccent)); } else { textView.setBackground(/*from ww w.j a va 2s . com*/ ContextCompat.getDrawable(getActivity(), R.drawable.text_view_card_style_grey)); textView.setTextColor(ContextCompat.getColor(getActivity(), R.color.material_grey)); } textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { DURING[week] = !DURING[week]; } }); GridLayout.Spec row = GridLayout.spec(i, 1, 1); GridLayout.Spec col = GridLayout.spec(j, 1, 1); GridLayout.LayoutParams params = new GridLayout.LayoutParams(row, col); gridLayout.addView(textView, params); selections[i][j] = textView; } } }
From source file:com.jasonchen.microlang.view.LinearViewPagerIndicator.java
public void addTab(String title) { if (mMeasured) { throw new IllegalStateException("Cannot add tabs when measured"); }/*www. j a v a2s. c o m*/ TextView tv = new TextView(mContext); tv.setText(title); tv.setTextColor(mForeground); tv.setGravity(Gravity.CENTER); tv.setTag(getChildCount()); tv.setOnClickListener(this); tv.setBackground(getBackground()); LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); params.weight = 1.0f; addView(tv, params); }
From source file:com.ofalvai.bpinfo.util.UiUtils.java
/** * Adds a rectangular icon for the affected route. * * First it creates a TextView, then sets the style properties of the view. * The custom colored rounded background is achieved by a Drawable and a ColorFilter on top of that. *///from www . j a va 2 s . c om public static void addRouteIcon(Context context, @NonNull ViewGroup root, @NonNull Route route) { ContextThemeWrapper iconContextTheme = new ContextThemeWrapper(context, R.style.RouteIcon); TextView iconView = new TextView(iconContextTheme); iconView.setText(route.getShortName()); iconView.setTextColor(route.getTextColor()); iconView.setContentDescription(Utils.getContentDescriptionForRoute(context, route)); root.addView(iconView); // Layout attributes defined in R.style.RouteIcon were ignored before attaching the view to // a parent, so we need to manually set them ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) iconView.getLayoutParams(); params.width = ViewGroup.LayoutParams.WRAP_CONTENT; int margin = (int) context.getResources().getDimension(R.dimen.route_icon_margin); params.rightMargin = margin; params.topMargin = margin; // A requestLayout() call is not necessary here because the setBackground() method below // will call that anyway. //iconView.requestLayout(); // Setting a custom colored rounded background drawable as background Drawable iconBackground = context.getResources().getDrawable(R.drawable.rounded_corner_5dp); if (iconBackground != null) { ColorFilter colorFilter = new LightingColorFilter(Color.rgb(1, 1, 1), route.getColor()); iconBackground.mutate().setColorFilter(colorFilter); iconView.setBackground(iconBackground); } }
From source file:com.houseofslack.pullscoring.Scoring.java
private void changeInputFocus(int oldInputId, int newInputId) { TextView oldInput = (TextView) findViewById(oldInputId); TextView newInput = (TextView) findViewById(newInputId); newInput.setBackground(getResources().getDrawable(R.drawable.score_input_focused)); newInput.setTextColor(getResources().getColor(R.color.focused_text_color)); oldInput.setBackground(getResources().getDrawable(R.drawable.score_input_normal)); oldInput.setTextColor(getResources().getColor(R.color.normal_text_color)); mCurrentFocus = newInputId;//from w w w .j a v a2 s . com }
From source file:git.egatuts.nxtremotecontroller.activity.ControllerActivity.java
public View createTabView(Context context, int resId, String text) { View view = LayoutInflater.from(context).inflate(resId, null); TextView title = (TextView) view.findViewById(R.id.tab_title); title.setText(text);//w w w. j ava 2 s . co m if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { title.setBackground(this.tabDrawableList.getConstantState().newDrawable()); } else { title.setBackgroundDrawable(this.tabDrawableList.getConstantState().newDrawable()); } title.setTextColor(this.tabColorList); return view; }
From source file:de.kodejak.hashr.fragmentHashFromText.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;/*from ww w . ja v a2 s . 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.ltf.mytoolslibrary.viewbase.viewPagerGuidanceActivityMyLib.SpringIndicator.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void addTabItems() { LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(20, 20); tabs = new ArrayList<>(); layoutParams.setMargins(15, 0, 15, 0); for (int i = 0; i < viewPager.getAdapter().getCount(); i++) { TextView textView = new TextView(getContext()); if (viewPager.getAdapter().getPageTitle(i) != null) { textView.setText(viewPager.getAdapter().getPageTitle(i)); }//from ww w .j ava 2s .c om textView.setGravity(Gravity.CENTER); // textView.setBackground(getResources().getDrawable(R.drawable.steward_msg_red)); textView.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.circle_orange)); textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); textView.setTextColor(getResources().getColor(textColorId)); if (textBgResId != 0) { textView.setBackgroundResource(textBgResId); } textView.setLayoutParams(layoutParams); final int position = i; textView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (tabClickListener == null || tabClickListener.onTabClick(position)) { viewPager.setCurrentItem(position); } } }); tabs.add(textView); tabContainer.addView(textView); } }