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.astuetz.PagerSlidingTabStripCustom.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, textSize);//TODO
            //            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            //                tab.setTextColor(tabTextColor);
            tab.setTextColor(textColor);//TODO

            // 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  ww  .j av a2  s. c  om*/
            }
            //TODO  ?pageTitle?
            if (mCurrentPosition == i) {
                tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, selectTextSize);
                tab.setTextColor(selectTextColor);
            }
        }
    }

}

From source file:so.contacts.hub.basefunction.widget.viewpagerindicator.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);

            // 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 ww. jav  a 2  s .c om
            }
        }
    }

}

From source file:com.gome.haoyuangong.views.MyViewPageIndicator.java

private void addTab(int index, CharSequence text, int iconResId) {
    final TabView tabView = new TabView(getContext());
    tabView.mIndex = index;/*w  ww.ja  va  2s .  c o m*/
    tabView.setTag("tavView");
    tabView.setId(index);
    //      tabView.setFocusable(true);
    //      tabView.setOnClickListener(mTabClickListener);
    tabView.setText(text);
    //tabView.setPadding(pointSize, 0, pointSize, 0);
    tabView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    tabView.setMaxLines(1);
    tabView.setGravity(Gravity.CENTER);
    XmlPullParser xrp = getResources().getXml(R.drawable.tab_button);
    try {
        ColorStateList csl = ColorStateList.createFromXml(getResources(), xrp);
        tabView.setTextColor(csl);
    } catch (Exception e) {

    }

    if (iconResId != 0) {
        //tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
    }

    FrameLayout.LayoutParams tabTvL = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tabView.setLayoutParams(tabTvL);

    //measureView(tabView);

    LinearLayout layoutWraper1 = new LinearLayout(getContext());
    LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, 1);
    layoutWraper1.setLayoutParams(lp1);
    layoutWraper1.setGravity(Gravity.CENTER);
    layoutWraper1.setFocusable(true);
    layoutWraper1.setOnClickListener(mTabClickListener);
    layoutWraper1.setPadding(0, 0, 0, 0);
    layoutWraper1.setBackgroundResource(R.drawable.tab_btn_red);

    FrameLayout frameLayout = new FrameLayout(getContext());
    frameLayout.setTag("framelayout");
    //      FrameLayout.LayoutParams fl2 = new FrameLayout.LayoutParams(tabView.getMeasuredWidth() + padding, tabView.getMeasuredHeight()+ (int)(padding * 1.5));
    FrameLayout.LayoutParams fl2 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    //      frameLayout.setPadding(padding, padding, padding, padding);
    frameLayout.setLayoutParams(fl2);
    //      frameLayout.addView(tabView);

    View hasNew = new View(getContext());
    FrameLayout.LayoutParams hasNewL = new FrameLayout.LayoutParams(pointSize, pointSize);
    hasNew.setLayoutParams(hasNewL);
    hasNewL.gravity = Gravity.TOP | Gravity.RIGHT;
    hasNew.setBackgroundResource(R.drawable.shape_circle);

    FrameLayout tabTvframe = new FrameLayout(getContext());
    FrameLayout.LayoutParams tabTvframeL = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tabTvframeL.gravity = Gravity.CENTER;
    tabTvframe.setLayoutParams(tabTvframeL);
    tabTvframe.addView(tabView);
    tabTvframe.addView(hasNew);
    hasNew.setVisibility(View.GONE);

    frameLayout.addView(tabTvframe);

    layoutWraper1.addView(frameLayout);

    tabView.setTagView(hasNew);

    mTabLayout.addView(layoutWraper1, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1));
}

From source file:com.baseutil.strip.PagerSlidingTabStrip.java

private void updateTabTextColorStyles(int pos, int color, int unselectedcolor) {

    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);
            if (pos == i) {
                tab.setTextColor(color);
            } else {
                tab.setTextColor(unselectedcolor);
            }//from w  ww . j  a  va2 s  . c  o m
            if (tabResources != null) {
                tab.setCompoundDrawablesWithIntrinsicBounds(tabResources[i], 0, 0, 0);
            }
            // 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:net.coding.program.third.MyPagerSlidingTabStrip.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);

            // 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   ww  w .j a va 2 s .c o  m*/
            }
        }
    }

}

From source file:com.hcpt.fastfood.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_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));
                }/* w w  w . j  a  va2  s  .c o m*/
            }
        }
    }

}

From source file:com.astuetz.PagerSlidingTitleIconTabStrip.java

private void updateTabStyles() {

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

        View v = tabsContainer.getChildAt(i);

        v.setBackgroundResource(tabBackgroundResId);

        if (v instanceof LinearLayout) {
            if (((LinearLayout) v).getChildCount() > 1) {
                v = ((LinearLayout) v).getChildAt(1);
            } else {
                v = ((LinearLayout) v).getChildAt(0);
            }// ww w  .ja  v a  2 s .  co m
        }

        if (v instanceof TextView) {
            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            if (i == currentPageSelected) {
                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));
                }
            }
        }
    }

}

From source file:com.pinthecloud.item.view.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(tabSwitch && i != startTab ? tabDeactivateTextColor : tabTextColor);

            if (textAllCaps) {
                tab.setAllCaps(true);/* w w  w .j av a 2s . co  m*/
            }
        } else if (v instanceof ImageButton) {
            ImageButton tab = (ImageButton) v;
            tab.setSelected(tabSwitch && i == startTab ? true : false);
        } else {
            v.setSelected(tabSwitch && i == startTab ? true : false);
        }
    }
}

From source file:lenidh.android.holochron.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // Theme needs to be selected before super.onCreate.
    if (App.getThemePreference().equals(getString(R.string.pref_value_theme_dark))
            || App.getThemePreference().equals(getString(R.string.pref_value_theme_classic))) {
        setTheme(R.style.AppTheme_Dark);
    }//from ww  w  . jav  a  2  s  .  co m

    super.onCreate(savedInstanceState);

    if (App.getThemePreference().equals(getString(R.string.pref_value_theme_classic))) {
        setContentView(R.layout.activity_main_classic);
    } else {
        setContentView(R.layout.activity_main);
    }

    /* state button */

    this.btnState = (Button) this.findViewById(R.id.btnState);
    this.btnState.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onStartStop();
        }
    });

    /* extra button */

    this.btnExtra = (Button) this.findViewById(R.id.btnExtra);
    this.btnExtra.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onResetRecord();
        }
    });

    // Configure dark theme.
    if (App.getThemePreference().equals(getString(R.string.pref_value_theme_dark))) {
        LinearLayout tile = (LinearLayout) this.findViewById(R.id.tile);
        View hView = this.findViewById(R.id.hSeparator);
        View vView = this.findViewById(R.id.vSeparator);
        View landSeparator = this.findViewById(R.id.landSeparator);

        tile.setBackgroundResource(R.drawable.tile_shape_dark);
        hView.setBackgroundResource(R.color.watch_button_separator_color_dark);
        vView.setBackgroundResource(R.color.watch_button_separator_color_dark);
        if (landSeparator != null)
            landSeparator.setBackgroundResource(android.R.color.white);
        this.btnState.setTextColor(getResources().getColor(android.R.color.white));
        this.btnExtra.setTextColor(getResources().getColor(android.R.color.white));
    }

    /* display */

    this.display = (DigitalDisplay) this.findViewById(R.id.digitalDisplay1);

    /* elapsed time Adapter */

    this.elapsedTimeArrayAdapter = new ElapsedTimeLapAdapter(this, App.getWatch().getLapContainer());

    /* lap time Adapter */

    LapTimeLapAdapter.SortOrder sortOrder = this.getLapTimeMode();
    this.lapTimeArrayAdapter = new LapTimeLapAdapter(this, App.getWatch().getLapContainer(), sortOrder);

    /* lap pages */

    // Find pager view.
    this.lapPager = (ViewPager) this.findViewById(R.id.lapPager);
    this.lapPager.setOnPageChangeListener(this);
    ArrayList<LapListFragment> pages = new ArrayList<LapListFragment>();

    // Check if page was already created and create page if necessary.
    LapListFragment elapsedTimeListFragment = (LapListFragment) getSupportFragmentManager()
            .findFragmentByTag("android:switcher:" + lapPager.getId() + ":0");
    if (elapsedTimeListFragment == null)
        elapsedTimeListFragment = new LapListFragment();
    elapsedTimeListFragment.setListAdapter(this.elapsedTimeArrayAdapter);
    pages.add(elapsedTimeListFragment);

    // Check if page was already created and create page if necessary.
    this.lapTimeListFragment = (LapListFragment) getSupportFragmentManager()
            .findFragmentByTag("android:switcher:" + lapPager.getId() + ":1");
    if (lapTimeListFragment == null)
        this.lapTimeListFragment = new LapListFragment();
    this.lapTimeListFragment.setListAdapter(this.lapTimeArrayAdapter);
    pages.add(this.lapTimeListFragment);

    // Create the page adapter.
    LapPagerAdapter lapPagerAdapter = new LapPagerAdapter(getSupportFragmentManager());
    lapPagerAdapter.setPages(pages);

    // Add page adapter to pager.
    this.lapPager.setAdapter(lapPagerAdapter);
}

From source file:com.gx.appstore.lib.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);

            // 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 ww. j  ava  2 s. c  om
            }
            // 
            if (i == mCurSelectedPos) {
                tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSizeSelected);
                tab.setTextColor(tabTextColorSelected);
            }
        }
    }

}