Example usage for android.widget TextView setBackgroundResource

List of usage examples for android.widget TextView setBackgroundResource

Introduction

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

Prototype

@RemotableViewMethod
public void setBackgroundResource(@DrawableRes int resid) 

Source Link

Document

Set the background to a given resource.

Usage

From source file:com.edvaldotsi.fastfood.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 ww.  j  ava 2s .co 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.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f));

    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);

    return textView;
}

From source file:ru.b7.rtphysics.google.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)}.//  w w  w .ja v  a 2s . c  om
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(18);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    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);

    return textView;
}

From source file:org.telegram.ui.ActionBar.ActionBarMenuItem.java

public TextView addSubItem(int id, String text, int icon) {
    if (popupLayout == null) {
        rect = new Rect();
        location = new int[2];
        popupLayout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(getContext());
        popupLayout.setOnTouchListener(new OnTouchListener() {
            @Override//from  w w w .  j a  v a 2  s  . c om
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                    if (popupWindow != null && popupWindow.isShowing()) {
                        v.getHitRect(rect);
                        if (!rect.contains((int) event.getX(), (int) event.getY())) {
                            popupWindow.dismiss();
                        }
                    }
                }
                return false;
            }
        });
        popupLayout.setDispatchKeyEventListener(new ActionBarPopupWindow.OnDispatchKeyEventListener() {
            @Override
            public void onDispatchKeyEvent(KeyEvent keyEvent) {
                if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && keyEvent.getRepeatCount() == 0
                        && popupWindow != null && popupWindow.isShowing()) {
                    popupWindow.dismiss();
                }
            }
        });
    }
    TextView textView = new TextView(getContext());
    textView.setTextColor(ContextCompat.getColor(getContext(), R.color.primary_text));
    textView.setBackgroundResource(R.drawable.list_selector);
    if (!LocaleController.isRTL) {
        textView.setGravity(Gravity.CENTER_VERTICAL);
    } else {
        textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
    }
    textView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    textView.setMinWidth(AndroidUtilities.dp(196));
    textView.setTag(id);
    textView.setText(text);
    if (icon != 0) {
        textView.setCompoundDrawablePadding(AndroidUtilities.dp(12));
        if (!LocaleController.isRTL) {
            textView.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(icon), null, null,
                    null);
        } else {
            textView.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(icon),
                    null);
        }
    }
    popupLayout.setShowedFromBotton(showFromBottom);
    popupLayout.addView(textView);
    LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) textView.getLayoutParams();
    if (LocaleController.isRTL) {
        layoutParams.gravity = Gravity.RIGHT;
    }
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = AndroidUtilities.dp(48);
    textView.setLayoutParams(layoutParams);
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (popupWindow != null && popupWindow.isShowing()) {
                if (processedPopupClick) {
                    return;
                }
                processedPopupClick = true;
                popupWindow.dismiss(allowCloseAnimation);
            }
            if (parentMenu != null) {
                parentMenu.onItemClick((Integer) view.getTag());
            } else if (delegate != null) {
                delegate.onItemClick((Integer) view.getTag());
            }
        }
    });
    menuHeight += layoutParams.height;
    return textView;
}

From source file:com.crone.skillbranchtest.utils.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)}.// w ww  .ja va  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.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);

    return textView;
}

From source file:com.zhongsou.souyue.ui.indicator.IcommonTabPageIndicator.java

private void addTab(CharSequence text, int index) {
    //      final TabView tabView = new TabView(getContext());
    //      tabView.mIndex = index;
    final TextView tabView = new TextView(getContext());
    tabView.setTag(index);//from   w w  w .  j a v a 2 s  . co m
    //      if (index == 0){
    //         doSetTextStyle(tabView, R.drawable.sy_indicator_icommentary_left);
    //      } else if (index == count - 1){
    //         doSetTextStyle(tabView, R.drawable.sy_indicator_icommentary_right);
    //      } else {
    //         doSetTextStyle(tabView, R.drawable.sy_indicator_icommentary_middle);
    //      }
    tabView.setBackgroundResource(R.drawable.vpi__tab_indicator_blue_line);
    tabView.setTextColor(getResources().getColor(R.color.bar_center_title_color));
    tabView.setGravity(Gravity.CENTER);
    tabView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    tabView.setPadding(30, 0, 30, 0);
    tabView.setFocusable(true);
    tabView.setOnClickListener(mTabClickListener);
    tabView.setText(text);

    mTabLayout.addView(tabView, new LinearLayout.LayoutParams(0, FILL_PARENT, 1));
}

From source file:com.example.id.moevents.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 . java 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.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);
    return textView;
}

From source file:fer.hr.ferapp.common.custom_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  w  ww  . ja v a 2  s. c o m*/
 */
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.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);
    return textView;
}

From source file:com.grottworkshop.gwsspringindicator.SpringIndicator.java

@SuppressWarnings("deprecation")
private void addTabItems() {
    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++) {
        TextView textView = new TextView(getContext());
        if (viewPager.getAdapter().getPageTitle(i) != null) {
            textView.setText(viewPager.getAdapter().getPageTitle(i));
        }/*from w  w  w. j  a  v a 2s  .  c o  m*/
        textView.setGravity(Gravity.CENTER);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        //TODO: getColor(int) is depreciated fix
        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);
    }
}

From source file:com.example.fugro.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 .java  2  s . co 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.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);

    return textView;
}

From source file:com.kalpnil.ksinfotech.tsec.tabs.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  av  a 2  s .c o m*/
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
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.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);
    return textView;
}