Example usage for android.view View setBackgroundResource

List of usage examples for android.view View setBackgroundResource

Introduction

In this page you can find the example usage for android.view View setBackgroundResource.

Prototype

@RemotableViewMethod
public void setBackgroundResource(@DrawableRes int resid) 

Source Link

Document

Set the background to a given resource.

Usage

From source file:com.junshan.pub.widget.PagerSlidingTabStrip.java

private void updateTabStyles() {
    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        v.setBackgroundResource(tabBackgroundResId);

        if (v instanceof TextView) {
            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_DIP, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            //tab.setTextColor(tabTextColor);

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            /*if (textAllCaps) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
              tab.setAllCaps(true);/*from w  w w. j  a v a  2s .  c  o m*/
            } else {
              tab.setText(tab.getText().toString().toUpperCase(locale));
            }
            }*/
        }
    }
    updateTabTextColor();
}

From source file:com.runApp.ui.utils.PagerSlidingTabStrip.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        v.setBackgroundResource(!tabSwitch ? tabBackgroundResId : transparentColorId);

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabSwitch && i != 0 ? tabDeactivateTextColor : tabTextColor);

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }//from   w w w. j  a  v a2 s  .  c  o m
            }
        } else if (v instanceof ImageButton) {
            ImageButton tab = (ImageButton) v;
            tab.setSelected(tabSwitch && i == 0 ? true : false);

        }

    }
}

From source file:com.yahala.ui.Views.PagerSlidingTabStrip.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        v.setBackgroundResource(!tabSwitch ? tabBackgroundResId : transparentColorId);

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabSwitch && i != 0 ? tabDeactivateTextColor : tabTextColor);

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }//  w  w  w .  j  av  a 2 s. co  m
            }
        } else if (v instanceof IconButton) {
            IconButton tab = (IconButton) v;
            tab.textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.textView.setTextColor(tabSwitch && i != 0 ? tabDeactivateTextColor : tabTextColor);
            v.setSelected(tabSwitch && i == 0 ? true : false);
        }
    }
}

From source file:com.pursuer.reader.easyrss.VerticalSingleItemView.java

private void updateButtonStar() {
    final View btnStar = menu.findViewById(R.id.BtnAddStar);
    if (item.getState().isStarred()) {
        btnStar.setBackgroundResource(R.drawable.menu_item_remove_star_xml);
    } else {//from   w w  w.j av a 2  s  .c  o  m
        btnStar.setBackgroundResource(R.drawable.menu_item_add_star_xml);
    }
    btnStar.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View view) {
            final boolean starred = !item.getState().isStarred();
            dataMgr.markItemAsStarredWithTransactionByUid(item.getUid(), starred);
            item.getState().setStarred(starred);
            Toast.makeText(context, starred ? R.string.MsgStarred : R.string.MsgUnstarred, Toast.LENGTH_LONG)
                    .show();
            updateButtonStar();
            NetworkMgr.getInstance().startImmediateItemStateSyncing();
        }
    });
}

From source file:com.linju.android_property.viewutils.PagerSlidingTabStrip.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        v.setBackgroundResource(tabBackgroundResId);

        if (v instanceof WPTextView) {

            WPTextView tab = (WPTextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            //            tab.setTextColor(tabTextColor);
            if (pager.getCurrentItem() == i) {
                tab.setTextColor(tabTextFocusColor);
            } else {
                tab.setTextColor(tabTextColor);
            }//from  w ww  .j a v a 2s.c  om
            //            tab.setTextColor(getResources().getColor(R.color.text_color_selector));

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }
            }
        }
    }

}

From source file:com.zhongsou.souyue.ui.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (isInEditMode() || tabCount == 0) {
        return;/*w ww. ja  v  a 2 s  .  c  o  m*/
    }

    final int height = getHeight();

    // draw indicator line

    rectPaint.setColor(indicatorColor);

    // default: line below current tab
    View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();

    for (int i = 0; i < tabCount; i++) {
        View v = tabsContainer.getChildAt(i);
        v.setBackgroundResource(tabBackgroundResId);
        if (i == currentPosition) {
            if (v instanceof TextView) {
                TextView tab = (TextView) v;
                tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
                tab.setTextColor(textColor);
            }
        } else {
            if (v instanceof TextView) {
                TextView tab = (TextView) v;
                tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
                tab.setTextColor(tabTextColor);
            }
        }
    }

    // if there is an offset, start interpolating left and right coordinates between current and next tab
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

        View nextTab = tabsContainer.getChildAt(currentPosition + 1);
        final float nextTabLeft = nextTab.getLeft();
        final float nextTabRight = nextTab.getRight();

        lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
        lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
    }

    canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);

    // draw underline

    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // draw divider

    dividerPaint.setColor(dividerColor);
    for (int i = 0; i < tabCount - 1; i++) {
        View tab = tabsContainer.getChildAt(i);
        canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
    }
}

From source file:com.astuetz.PagerSlidingTabStripMy.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        v.setBackgroundResource(tabBackgroundResId);

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, pstsTabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(pstsTabTextColor);

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }//from  w w w. j  a v  a2 s . c o m
            }

            if (mCurrentPosition == i) {
                tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, pstsSelectedTextSize);
                tab.setTypeface(tabTypeface, tabTypefaceStyle);
                tab.setTextColor(pstsSelecedTextcolor);
            }
        }
    }

}

From source file:com.tritop.androsense2.fragments.GpsFragment.java

private void setupViewBinders(SimpleAdapter adapter, final int stdColorResource, final int fixColorResource) {
    adapter.setViewBinder(new SimpleAdapter.ViewBinder() {

        @Override//from  w w  w  . ja  v a2  s  .  c om
        public boolean setViewValue(View view, Object data, String textRepresentation) {
            String gpsdata;
            switch (view.getId()) {
            case R.id.gpsfragment_sat_item_tv:
                gpsdata = (String) data;
                if (gpsdata.equals("TRUE")) {
                    view.setBackgroundResource(fixColorResource);
                } else if (gpsdata.equals("FALSE")) {
                    view.setBackgroundResource(stdColorResource);
                } else {
                    ((TextView) view).setText(gpsdata);
                }
                return true;
            default:
                return false;
            }
        }
    });
}

From source file:android.improving.utils.views.PagerSlidingTabStrip.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        v.setBackgroundResource(tabBackgroundResId);

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            //            tab.setTextColor(tabTextColor);

            animTextColor(tab, selectedTabTextColor, tabTextColor);

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }/*w  w w. ja v  a  2s  .co  m*/
            }
            if (i == selectedPosition) {
                //               tab.setTextColor(selectedTabTextColor);
                animTextColor(tab, tabTextColor, selectedTabTextColor);
                tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, selectedTabTextSize);
            }
        }
    }

}

From source file:com.android.biubiu.component.indicator.PagerSlidingTabStrip.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);
        if (tabBackgroundResId != 0) {
            v.setBackgroundResource(tabBackgroundResId);
        }/*from w  w  w.j av  a2s  .  co m*/

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabTextColor);

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            /*if (textAllCaps) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                tab.setAllCaps(true);
            } else {
                tab.setText(tab.getText().toString().toUpperCase(locale));
            }
            }*/
        }
    }

}