List of usage examples for android.widget TextView setBackgroundResource
@RemotableViewMethod public void setBackgroundResource(@DrawableRes int resid)
From source file:com.exc.zhen.orienteering.SlidingTabLayout.java
private void populateTabStrip() { final PagerAdapter adapter = mViewPager.getAdapter(); final OnClickListener tabClickListener = new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null;//from w w w .j a v a2 s . c o m TextView tabTitleView = null; if (mTabViewLayoutId != 0) { // If there is a custom tab view layout id set, try and inflate it tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false); tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); } if (tabView == null) { tabView = createDefaultTabView(getContext()); } if (tabTitleView == null && TextView.class.isInstance(tabView)) { tabTitleView = (TextView) tabView; } //tabView?(my) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); if (tabTitleView != null) { //tabTitleView.setBackgroundResource(outValue.resourceId); tabTitleView.setBackgroundResource(R.drawable.tab_color); } } //tabView?(my) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style if (tabTitleView != null) { tabTitleView.setAllCaps(true); } } if (tabTitleView != null) { tabTitleView.setText(adapter.getPageTitle(i)); } tabView.setOnClickListener(tabClickListener); mTabStrip.addView(tabView); } }
From source file:com.runtai.pullupsuspension.view.SlidingTabLayout.java
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}.//from w w w. j av a 2 s . com */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); // textView.setGravity(Gravity.CENTER); textView.setGravity(17); // textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTextSize(2, 12.0F); textView.setTypeface(Typeface.DEFAULT); textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); // TypedValue outValue = new TypedValue(); // getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, // outValue, true); // textView.setBackgroundResource(outValue.resourceId); // textView.setAllCaps(true); // // int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); // textView.setPadding(padding, padding, padding, padding); if (Build.VERSION.SDK_INT >= 11) { TypedValue localTypedValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, localTypedValue, true); textView.setBackgroundResource(localTypedValue.resourceId); } if (Build.VERSION.SDK_INT >= 14) { textView.setAllCaps(true); int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding + 30, padding, padding + 30, padding); } return textView; }
From source file:com.marcohc.robotocalendar.RobotoCalendarView.java
private void initializeDaysOfMonthLayout() { TextView dayOfMonthText; // View firstUnderline; // View secondUnderline; ViewGroup dayOfMonthContainer;//w w w. j a va 2 s . co m ViewGroup dayOfMonthBackground; for (int i = 1; i < 43; i++) { dayOfMonthContainer = (ViewGroup) view.findViewWithTag(DAY_OF_MONTH_CONTAINER + i); dayOfMonthBackground = (ViewGroup) view.findViewWithTag(DAY_OF_MONTH_BACKGROUND + i); dayOfMonthText = (TextView) view.findViewWithTag(DAY_OF_MONTH_TEXT + i); // firstUnderline = view.findViewWithTag(FIRST_UNDERLINE + i); // secondUnderline = view.findViewWithTag(SECOND_UNDERLINE + i); dayOfMonthText.setVisibility(View.INVISIBLE); // firstUnderline.setVisibility(View.INVISIBLE); // secondUnderline.setVisibility(View.INVISIBLE); // Apply styles dayOfMonthText.setBackgroundResource(android.R.color.transparent); dayOfMonthContainer.setBackgroundResource(android.R.color.transparent); dayOfMonthContainer.setOnClickListener(null); dayOfMonthBackground.setBackgroundResource(android.R.color.transparent); } }
From source file:com.sdspikes.fireworks.FireworksActivity.java
private TextView makeAttributeTextView(final int rank, final GameState.CardColor color) { LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); int oneButtonWidth = mDiscardWidthR2 / 10; int marginWidth = oneButtonWidth / 10; params.setMargins(marginWidth, 5, marginWidth, 5); params.width = oneButtonWidth - marginWidth * 2; params.height = params.width;/*from ww w .j av a2s.c om*/ TextView textView = new TextView(this); textView.setLayoutParams(params); textView.setText(String.valueOf(rank)); if (rank == -1) textView.setText(" "); textView.setGravity(Gravity.CENTER); textView.setBackgroundResource(HandFragment.cardColorToBGColor.get(color)); textView.setTextColor(getResources().getColor(HandFragment.cardColorToTextColor(color))); textView.setVisibility(View.VISIBLE); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.d(TAG, "clicked on an attribute button: " + GameState.Card.cardColorToString(color) + " " + rank); List<GameState.Card> hand = mTurnData.state.hands.get(mRecipientPlayer).hand; List<Integer> locations = new ArrayList<Integer>(); String info = ""; if (rank == -1) { info = GameState.Card.cardColorToString(color); for (int i = 0; i < hand.size(); i++) { if (hand.get(i).color == color) locations.add(i); } } else { info = HandFragment.rankToString(rank); for (int i = 0; i < hand.size(); i++) { if (hand.get(i).rank == rank) locations.add(i); } } if (locations.size() == 0) { Toast.makeText(FireworksActivity.this, mIdToName.get(mRecipientPlayer) + " does not have any " + info, Toast.LENGTH_SHORT); } else { int[] positions = new int[locations.size()]; for (int i = 0; i < positions.length; i++) { // Make the positions 1-indexed positions[i] = locations.get(i) + 1; } LogItem item = new InfoLogItem(mMyId, mRecipientPlayer, info, positions); actionLog.add(item.toString()); mTurnData.state.hintsRemaining--; mTurnData.state.currentPlayerId = mTurnData.state.hands .get(mTurnData.state.currentPlayerId).nextPlayerId; togglePlayOptionsVisible(PlayOptions.turnMessage); broadcastGameInfo(item.getJSONObject()); updateAllPlayers(mTurnData.getJSONObject()); mRecipientPlayer = null; } } }); return textView; }
From source file:com.honeywell.printer.indicator.TabPageIndicator.java
/** * ?/* w w w.j a v a 2 s . co m*/ * * @param index tab * @param count ? */ public void showTabMsgCountView(int index, int count, int res) { if (mTabLayout != null) { final TextView msgCountView = (TextView) mTabLayout.findViewById(index + ID_OFFSET); if (msgCountView != null) { final int color = getResources().getColor(R.color.new_msg_num_text_color); msgCountView.setTextColor(color); msgCountView.setGravity(Gravity.CENTER); msgCountView.setTypeface(Typeface.DEFAULT_BOLD); // final int paddingPixels = Tools.dp2px(2); int paddingPixels = (int) getResources().getDimension(R.dimen.indicator_num_padding); msgCountView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels); final LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); final int badgeMarginLeft = (int) getResources().getDimension(R.dimen.indicator_marginleft); final int badgeMarginBottom = (int) getResources().getDimension(R.dimen.indicator_marginbottom); params.gravity = Gravity.CENTER; params.setMargins(badgeMarginLeft, 0, 0, badgeMarginBottom); if (count == 0) { msgCountView.setVisibility(View.GONE); return; } else if (count > 99) { msgCountView.setText("99+"); msgCountView.setBackgroundResource(R.drawable.tab_msg_num_big_bg); } else { msgCountView.setText(String.valueOf(count)); msgCountView.setBackgroundResource(res); } msgCountView.setTextSize(11); msgCountView.setLayoutParams(params); msgCountView.setVisibility(View.VISIBLE); } } }
From source file:com.cairoconfessions.MainActivity.java
public void addLocation(View view) { TextView newView = new TextView(this); AutoCompleteTextView addLoc = ((AutoCompleteTextView) findViewById(R.id.addLocation)); String newLoc = addLoc.getText().toString(); ViewGroup locList = ((ViewGroup) findViewById(R.id.locations)); boolean notFound = true; for (int i = 0; i < locList.getChildCount(); i++) { if (newLoc.equals(((TextView) locList.getChildAt(i)).getText().toString())) notFound = false;/* www .j av a 2 s . c o m*/ break; } if (Arrays.asList(COUNTRIES).contains(newLoc) && notFound) { newView.setText(newLoc); newView.setClickable(true); newView.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { addItem(view); } }); float scale = getResources().getDisplayMetrics().density; newView.setGravity(17); newView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30); newView.setBackgroundResource(R.drawable.city2); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, (int) (150 * scale)); lp.setMargins((int) (0 * scale), (int) (0 * scale), (int) (0 * scale), (int) (2 * scale)); newView.setLayoutParams(lp); locList.addView(newView, 0); addLoc.setText(""); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(addLoc.getWindowToken(), 0); addLoc.setCursorVisible(false); } else { Toast.makeText(this, "Invalid location", Toast.LENGTH_LONG).show(); } }
From source file:com.geecko.QuickLyric.fragment.LyricsViewFragment.java
private void startEditTagsMode() { ImageButton editButton = (ImageButton) getActivity().findViewById(R.id.edit_tags_btn); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { editButton.setImageResource(R.drawable.ic_edit_anim); ((Animatable) editButton.getDrawable()).start(); } else// ww w.j a v a 2s. c o m editButton.setImageResource(R.drawable.ic_done); ((DrawerLayout) ((MainActivity) getActivity()).drawer) .setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); mRefreshLayout.setEnabled(false); getActivity().findViewById(R.id.refresh_fab).setEnabled(false); ((RefreshIcon) getActivity().findViewById(R.id.refresh_fab)).hide(); ((Toolbar) getActivity().findViewById(R.id.toolbar)).getMenu().clear(); TextSwitcher textSwitcher = ((TextSwitcher) getActivity().findViewById(R.id.switcher)); EditText songTV = (EditText) getActivity().findViewById(R.id.song); TextView artistTV = ((TextView) getActivity().findViewById(R.id.artist)); EditText newLyrics = (EditText) getActivity().findViewById(R.id.edit_lyrics); newLyrics.setTypeface(LyricsTextFactory.FontCache.get("light", getActivity())); newLyrics.setText(((TextView) textSwitcher.getCurrentView()).getText(), TextView.BufferType.EDITABLE); textSwitcher.setVisibility(View.GONE); newLyrics.setVisibility(View.VISIBLE); songTV.setInputType(InputType.TYPE_CLASS_TEXT); artistTV.setInputType(InputType.TYPE_CLASS_TEXT); songTV.setBackgroundResource(R.drawable.abc_textfield_search_material); artistTV.setBackgroundResource(R.drawable.abc_textfield_search_material); if (songTV.requestFocus()) { InputMethodManager imm = (InputMethodManager) getActivity().getApplicationContext() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.SHOW_IMPLICIT); } }
From source file:ir.rasen.charsoo.view.widgets.SlidingTabLayout.java
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}.//from www .j av a 2 s . c o m */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setTextColor(Color.parseColor(TAB_HOST_UNSELECTED_TEXT_COLOR)); // get screen size int measuredWidth = 0; int measuredHeight = 0; WindowManager w = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { Point size = new Point(); w.getDefaultDisplay().getSize(size); measuredWidth = size.x; measuredHeight = size.y; } else { Display d = w.getDefaultDisplay(); measuredWidth = d.getWidth(); measuredHeight = d.getHeight(); } textView.setLayoutParams( new ViewGroup.LayoutParams(measuredWidth / tabCount, ViewGroup.LayoutParams.MATCH_PARENT)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style textView.setAllCaps(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
From source file:com.honeywell.printer.indicator.TabPageIndicator.java
/** * // w ww .j a v a 2 s. co m * * @param index tab */ public void showTabRedDotView(int index, int res) { if (mTabLayout != null) { final TextView msgCountView = (TextView) mTabLayout.findViewById(index + ID_OFFSET); if (msgCountView != null) { int paddingPixels = (int) getResources().getDimension(R.dimen.indicator_num_padding); msgCountView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels); final LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); int badgeMarginLeft = 0; int badgeMarginBottom = 0; if (index < 2) { badgeMarginLeft = (int) getResources().getDimension(R.dimen.indicator_no_number_marginleft); badgeMarginBottom = (int) getResources().getDimension(R.dimen.indicator_no_number_marginbottom); } else { badgeMarginLeft = (int) getResources().getDimension(R.dimen.indicator_no_number_marginleft_2); badgeMarginBottom = (int) getResources() .getDimension(R.dimen.indicator_no_number_marginbottom_2); } params.gravity = Gravity.CENTER; params.setMargins(badgeMarginLeft, 0, 0, badgeMarginBottom); params.width = (int) getResources().getDimension(R.dimen.indicator_no_number_width); ; params.height = (int) getResources().getDimension(R.dimen.indicator_no_number_height); ; msgCountView.setBackgroundResource(res); msgCountView.setLayoutParams(params); msgCountView.setVisibility(View.VISIBLE); } } }
From source file:com.gh4a.IssueActivity.java
private void fillData() { new LoadCommentsTask(this).execute(); Typeface boldCondensed = getApplicationContext().boldCondensed; ListView lvComments = (ListView) findViewById(R.id.list_view); // set details inside listview header LayoutInflater infalter = getLayoutInflater(); LinearLayout mHeader = (LinearLayout) infalter.inflate(R.layout.issue_header, lvComments, false); mHeader.setClickable(false);//from ww w . j ava2s. c o m lvComments.addHeaderView(mHeader, null, false); RelativeLayout rlComment = (RelativeLayout) findViewById(R.id.rl_comment); if (!isAuthorized()) { rlComment.setVisibility(View.GONE); } TextView tvCommentTitle = (TextView) mHeader.findViewById(R.id.comment_title); mCommentAdapter = new CommentAdapter(IssueActivity.this, new ArrayList<Comment>(), mIssue.getNumber(), mIssue.getState(), mRepoOwner, mRepoName); lvComments.setAdapter(mCommentAdapter); ImageView ivGravatar = (ImageView) mHeader.findViewById(R.id.iv_gravatar); aq.id(R.id.iv_gravatar).image(GravatarUtils.getGravatarUrl(mIssue.getUser().getGravatarId()), true, false, 0, 0, aq.getCachedImage(R.drawable.default_avatar), AQuery.FADE_IN); ivGravatar.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { getApplicationContext().openUserInfoActivity(IssueActivity.this, mIssue.getUser().getLogin(), null); } }); TextView tvExtra = (TextView) mHeader.findViewById(R.id.tv_extra); TextView tvState = (TextView) mHeader.findViewById(R.id.tv_state); TextView tvTitle = (TextView) mHeader.findViewById(R.id.tv_title); TextView tvDescTitle = (TextView) mHeader.findViewById(R.id.desc_title); tvDescTitle.setTypeface(getApplicationContext().boldCondensed); tvDescTitle.setTextColor(Color.parseColor("#0099cc")); tvCommentTitle.setTypeface(getApplicationContext().boldCondensed); tvCommentTitle.setTextColor(Color.parseColor("#0099cc")); tvCommentTitle .setText(getResources().getString(R.string.issue_comments) + " (" + mIssue.getComments() + ")"); TextView tvDesc = (TextView) mHeader.findViewById(R.id.tv_desc); tvDesc.setMovementMethod(LinkMovementMethod.getInstance()); TextView tvMilestone = (TextView) mHeader.findViewById(R.id.tv_milestone); ImageView ivComment = (ImageView) findViewById(R.id.iv_comment); if (Gh4Application.THEME == R.style.DefaultTheme) { ivComment.setImageResource(R.drawable.social_send_now_dark); } ivComment.setBackgroundResource(R.drawable.abs__list_selector_holo_dark); ivComment.setPadding(5, 2, 5, 2); ivComment.setOnClickListener(this); tvExtra.setText(mIssue.getUser().getLogin() + "\n" + pt.format(mIssue.getCreatedAt())); tvState.setTextColor(Color.WHITE); if ("closed".equals(mIssue.getState())) { tvState.setBackgroundResource(R.drawable.default_red_box); tvState.setText("C\nL\nO\nS\nE\nD"); } else { tvState.setBackgroundResource(R.drawable.default_green_box); tvState.setText("O\nP\nE\nN"); } tvTitle.setText(mIssue.getTitle()); tvTitle.setTypeface(boldCondensed); boolean showInfoBox = false; if (mIssue.getAssignee() != null) { showInfoBox = true; TextView tvAssignee = (TextView) mHeader.findViewById(R.id.tv_assignee); tvAssignee.setText(mIssue.getAssignee().getLogin() + " is assigned"); tvAssignee.setVisibility(View.VISIBLE); tvAssignee.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { getApplicationContext().openUserInfoActivity(IssueActivity.this, mIssue.getAssignee().getLogin(), null); } }); ImageView ivAssignee = (ImageView) mHeader.findViewById(R.id.iv_assignee); aq.id(R.id.iv_assignee).image(GravatarUtils.getGravatarUrl(mIssue.getAssignee().getGravatarId()), true, false, 0, 0, aq.getCachedImage(R.drawable.default_avatar), AQuery.FADE_IN); ivAssignee.setVisibility(View.VISIBLE); ivAssignee.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { getApplicationContext().openUserInfoActivity(IssueActivity.this, mIssue.getAssignee().getLogin(), null); } }); } if (mIssue.getMilestone() != null) { showInfoBox = true; tvMilestone.setText( getResources().getString(R.string.issue_milestone) + ": " + mIssue.getMilestone().getTitle()); } else { tvMilestone.setVisibility(View.GONE); } String body = mIssue.getBodyHtml(); if (!StringUtils.isBlank(body)) { HttpImageGetter imageGetter = new HttpImageGetter(this); body = HtmlUtils.format(body).toString(); imageGetter.bind(tvDesc, body, mIssue.getNumber()); } LinearLayout llLabels = (LinearLayout) findViewById(R.id.ll_labels); List<Label> labels = mIssue.getLabels(); if (labels != null && !labels.isEmpty()) { showInfoBox = true; for (Label label : labels) { TextView tvLabel = new TextView(this); tvLabel.setSingleLine(true); tvLabel.setText(label.getName()); tvLabel.setTextAppearance(this, R.style.default_text_small); tvLabel.setBackgroundColor(Color.parseColor("#" + label.getColor())); tvLabel.setPadding(5, 2, 5, 2); int r = Color.red(Color.parseColor("#" + label.getColor())); int g = Color.green(Color.parseColor("#" + label.getColor())); int b = Color.blue(Color.parseColor("#" + label.getColor())); if (r + g + b < 383) { tvLabel.setTextColor(getResources().getColor(android.R.color.primary_text_dark)); } else { tvLabel.setTextColor(getResources().getColor(android.R.color.primary_text_light)); } llLabels.addView(tvLabel); View v = new View(this); v.setLayoutParams(new LayoutParams(5, LayoutParams.WRAP_CONTENT)); llLabels.addView(v); } } else { llLabels.setVisibility(View.GONE); } TextView tvPull = (TextView) mHeader.findViewById(R.id.tv_pull); if (mIssue.getPullRequest() != null && mIssue.getPullRequest().getDiffUrl() != null) { showInfoBox = true; tvPull.setVisibility(View.VISIBLE); tvPull.setOnClickListener(this); } if (!showInfoBox) { RelativeLayout rl = (RelativeLayout) mHeader.findViewById(R.id.info_box); rl.setVisibility(View.GONE); } }