List of usage examples for android.widget TextView setBackgroundResource
@RemotableViewMethod public void setBackgroundResource(@DrawableRes int resid)
From source file:com.zuzhili.ui.views.PagerSlidingTabStrip.java
private void updateTabStyles() { defaultTabLayoutParams = new LinearLayout.LayoutParams(widthPixels / tabCount, LayoutParams.FILL_PARENT); expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.FILL_PARENT, 1.0f); for (int i = 0; i < tabCount; i++) { TextView tab = (TextView) tabsContainer.getChildAt(i); tab.setLayoutParams(defaultTabLayoutParams); tab.setBackgroundResource(tabBackgroundResId); if (shouldExpand) { tab.setPadding(0, 0, 0, 0);//from w w w .jav a2s.c o m } else { tab.setPadding(tabPadding, 0, tabPadding, 0); } tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); tab.setTypeface(tabTypeface, tabTypefaceStyle); tab.setTextColor(tabTextColor); // modified if (currentPosition == i) { tab.setTextColor(tabTextColorWhenSelected); } else { tab.setTextColor(tabTextColor); } } }
From source file:justforcommunity.radiocom.views.SlidingTabLayout.java
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); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { textView.setAllCaps(true);/*from w w w.j ava2 s .c o m*/ } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
From source file:com.acrylicgoat.houstonbicyclemuseum.view.SlidingTabLayout.java
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); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); }/*from w ww. j a v a 2s . c om*/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { 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.oldfeel.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. ja v a2 s . com */ 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); 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); int count = mViewPager.getAdapter().getCount(); if (count > 0 && count <= 4) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size); textView.setWidth(size.x / count); } return textView; }
From source file:com.bwash.bwashcar.view.PagerSlidingTabStrip.java
private void addTextTab(final int position, String title, int res) { View view = View.inflate(getContext(), R.layout.tab_item_layout, null); TextView tab = (TextView) view.findViewById(R.id.text); tab.setText(title);// w w w .j a v a 2 s.c om tab.setSingleLine(); tab.setBackgroundResource(R.color.white); tab.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(res), null, null, null); tab.setCompoundDrawablePadding(ViewUtils.dip2px(getContext(), 5)); addTab(position, view); }
From source file:com.mickledeals.views.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 ww w . j a v 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_PX, context.getResources().getDimensionPixelSize(R.dimen.sp_17)); textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setTextColor(Color.argb((int) (MIN_TEXT_ALPHA * 255), 255, 255, 255)); textView.setBackgroundResource(R.drawable.selector_bg); // 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.example.emamianrizif.Movie.views.SlidingTabLayout.java
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); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); }//from w w w.j av a2 s .c om if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { 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.fjoglar.etsitnoticias.utils.UiUtils.java
/** * Configure the TextViews that will show the attachments of the new. * * @param textView TextView to be configured. * @param title Text shown in TextView * @param downloadLink Link attached to TextView. * @param fileType Type of file of the attachment. * @param context The context of activity. */// w w w . j a v a2s . com public static void configureTextView(TextView textView, String title, final String downloadLink, Attachment.FILE_TYPE fileType, final Context context) { final int TEXT_VIEW_MIN_HEIGHT = 40; final int TEXT_VIEW_MARGIN_TOP = 4; LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.setMargins(0, convertDpToPx(TEXT_VIEW_MARGIN_TOP, context), 0, 0); textView.setLayoutParams(params); textView.setText(title); textView.setTypeface(Typeface.create("sans-serif-condensed", Typeface.NORMAL)); textView.setMinHeight(convertDpToPx(TEXT_VIEW_MIN_HEIGHT, context)); textView.setGravity(Gravity.CENTER_VERTICAL); switch (fileType) { case FILE: textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_file, 0, 0, 0); break; case IMAGE: textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_photo, 0, 0, 0); break; case FOLDER: textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_folder, 0, 0, 0); break; default: textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_link, 0, 0, 0); break; } textView.setCompoundDrawablePadding(convertDpToPx(4, context)); TypedValue typedValue = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true); textView.setBackgroundResource(typedValue.resourceId); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Navigator.getInstance().openUrl(context, downloadLink); } }); }
From source file:android.view.SpringIndicator.java
private void addTabItems() { final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f); tabs = new ArrayList<>(); for (int i = 0; i < viewPager.getAdapter().getCount(); i++) { final TextView textView = new TextView(getContext()); if (viewPager.getAdapter().getPageTitle(i) != null) textView.setText(viewPager.getAdapter().getPageTitle(i)); textView.setGravity(Gravity.CENTER); 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/* w ww .j ava 2 s .c om*/ public void onClick(final View v) { if (tabClickListener == null || tabClickListener.onTabClick(position)) viewPager.setCurrentItem(position); } }); tabs.add(textView); tabContainer.addView(textView); } }
From source file:za.jamie.soundstage.widgets.PagerSlidingTabStrip.java
private void updateTabStyles() { for (int i = 0; i < tabCount; i++) { TextView tab = (TextView) tabsContainer.getChildAt(i); tab.setLayoutParams(defaultTabLayoutParams); tab.setBackgroundResource(tabBackgroundResId); if (shouldExpand) { tab.setPadding(0, 0, 0, 0);// w ww . j a v a 2s . c o m } else { tab.setPadding(tabPadding, 0, tabPadding, 0); } tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); tab.setTypeface(tabTypeface, tabStyleIndex); tab.setTextColor(tabTextColor); if (textAllCaps) { tab.setAllCaps(true); } } }