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.andrewshu.android.reddit.common.Common.java

public static void updateNextPreviousButtons(ListActivity act, View nextPreviousView, String after,
        String before, int count, RedditSettings settings, OnClickListener downloadAfterOnClickListener,
        OnClickListener downloadBeforeOnClickListener) {
    boolean shouldShow = after != null || before != null;
    Button nextButton = null;/*w w  w.jav  a2s .  c om*/
    Button previousButton = null;

    // If alwaysShowNextPrevious, use the navbar
    if (settings.isAlwaysShowNextPrevious()) {
        nextPreviousView = act.findViewById(R.id.next_previous_layout);
        if (nextPreviousView == null)
            return;
        View nextPreviousBorder = act.findViewById(R.id.next_previous_border_top);

        if (shouldShow) {
            if (nextPreviousView != null && nextPreviousBorder != null) {
                if (Util.isLightTheme(settings.getTheme())) {
                    nextPreviousView.setBackgroundResource(android.R.color.background_light);
                    nextPreviousBorder.setBackgroundResource(R.color.black);
                } else {
                    nextPreviousBorder.setBackgroundResource(R.color.white);
                }
                nextPreviousView.setVisibility(View.VISIBLE);
            }
            // update the "next 25" and "prev 25" buttons
            nextButton = (Button) act.findViewById(R.id.next_button);
            previousButton = (Button) act.findViewById(R.id.previous_button);
        } else {
            nextPreviousView.setVisibility(View.GONE);
        }
    }
    // Otherwise we are using the ListView footer
    else {
        if (nextPreviousView == null)
            return;
        if (shouldShow && nextPreviousView.getVisibility() != View.VISIBLE) {
            nextPreviousView.setVisibility(View.VISIBLE);
        } else if (!shouldShow && nextPreviousView.getVisibility() == View.VISIBLE) {
            nextPreviousView.setVisibility(View.GONE);
        }
        // update the "next 25" and "prev 25" buttons
        nextButton = (Button) nextPreviousView.findViewById(R.id.next_button);
        previousButton = (Button) nextPreviousView.findViewById(R.id.previous_button);
    }
    if (nextButton != null) {
        if (after != null) {
            nextButton.setVisibility(View.VISIBLE);
            nextButton.setOnClickListener(downloadAfterOnClickListener);
        } else {
            nextButton.setVisibility(View.INVISIBLE);
        }
    }
    if (previousButton != null) {
        if (before != null && count != Constants.DEFAULT_THREAD_DOWNLOAD_LIMIT) {
            previousButton.setVisibility(View.VISIBLE);
            previousButton.setOnClickListener(downloadBeforeOnClickListener);
        } else {
            previousButton.setVisibility(View.INVISIBLE);
        }
    }
}

From source file:xyz.yhsj.helper.ViewHolderHelper.java

/**
 * @param viewId/*  ww  w .  j a  v a2s. c  o m*/
 * @param backgroundResId ?id
 * @return
 */
public ViewHolderHelper setBackgroundRes(@IdRes int viewId, int backgroundResId) {
    View view = getView(viewId);
    view.setBackgroundResource(backgroundResId);
    return this;
}

From source file:bigshots.people_helping_people.scroll_iew_lib.PagerSlidingTabStrip.java

private void updateTextColor() {
    for (int i = 0; i < tabCount; i++) {
        final View v = tabsContainer.getChildAt(i);
        v.setBackgroundResource(tabBackgroundResId);
        if (v instanceof TextView) {
            ((TextView) v).setTextColor(tabTextColor);
        }/* w  w w .ja  v  a2 s .  c o  m*/
    }

    final float min = currentPosition - 0.15f;
    final float max = currentPosition + 0.15f;
    final float pos = currentPosition + currentPositionOffset;
    //Todo optimise
    int i;
    if (pos > max)
        i = currentPosition + 1;
    else if (pos < min || pos <= max)
        i = currentPosition;
    else //(pos>=min)
        i = currentPosition + 1;

    final View v = tabsContainer.getChildAt(i);
    if (v instanceof TextView) {
        ((TextView) v).setTextColor(underlineColor);
    }

}

From source file:jm.org.data.area.IndicatorActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // only for android newer than gingerbread
        // ActionBar actionBar = getActionBar();
        // actionBar.setDisplayHomeAsUpEnabled(true);
    }//  w w w .j a va  2 s. c o m

    final Bundle indicatorBundle = getIntent().getExtras();
    if (indicatorBundle.getString(WB_INDICATOR_ID) != null) {

        indicatorID = indicatorBundle.getString(WB_INDICATOR_ID);
        indicator = indicatorBundle.getInt("ind_id");
        mGroupPosition = indicatorBundle.getInt(GROUP_POSITION);
        mChildPosition = indicatorBundle.getInt(CHILD_POSITION);
        mSelection = indicatorBundle.getInt(SELECTION_ID);
        selection = indicatorBundle.getString(SELECTION_NAME);

    } else if (indicatorBundle.getString(SELECTION_NAME) != null) {

        mSelection = indicatorBundle.getInt(SELECTION_ID);
        selection = indicatorBundle.getString(SELECTION_NAME);
    }

    if (indicatorBundle.getString("countries") != null) {
        countryList = new ArrayList<String>();
        String[] countryArray = indicatorBundle.getString("countries").split(",");

        countryList = new ArrayList<String>(Arrays.asList(countryArray));
    } else {
        countryList = new ArrayList<String>();

        countryList.add("World");
    }

    setContentView(R.layout.indicator_dashboard);
    //dialog = new ProgressDialog(this);
    mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup();

    mViewPager = (ViewPager) findViewById(R.id.viewpager);

    mTabsAdapter = new AreaTabsAdapter(this, mTabHost, mViewPager);

    mTabsAdapter.addTab(mTabHost.newTabSpec("charts").setIndicator("Charts"), ChartsFragment.class, null);
    mTabsAdapter.addTab(mTabHost.newTabSpec("articles").setIndicator("Articles"), ArticlesFragment.class, null);
    mTabsAdapter.addTab(mTabHost.newTabSpec("reports").setIndicator("Reports"), ReportsFragment.class, null);
    //mTabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);

    for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) {
        View v = mTabHost.getTabWidget().getChildAt(i);
        v.setBackgroundResource(R.drawable.tab_selector);
        TextView tv = (TextView) mTabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); //Unselected Tabs
        tv.setTextColor(Color.parseColor("#025E6B"));
    }
    View v = mTabHost.getCurrentTabView();
    v.setBackgroundResource(R.drawable.tab_selector);
    TextView tv = (TextView) mTabHost.getCurrentTabView().findViewById(android.R.id.title); //for Selected Tab
    tv.setTextColor(Color.parseColor("#025E6B"));

    if (savedInstanceState != null) {
        mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
    }

    // mListPosition = indicatorBundle.getInt(POSITION, -1);
    /*
     * if (mListPosition != -1) { IndicatorListFragment inFragment =
     * (IndicatorListFragment)
     * getSupportFragmentManager().findFragmentById(R.id.inlistFragment); if
     * (inFragment != null && inFragment.isInLayout()) {
     * inFragment.setListSelection(mListPosition); } }
     */
    Log.d(TAG, String.format("Indicator ID: %s at position %d", indicatorID, mChildPosition));

}

From source file:com.hao.common.adapter.BaseViewHolderHelper.java

/**
 * @param viewId/* w w  w .  j  av a2s .c o m*/
 * @param backgroundResId ?id
 * @return
 */
public BaseViewHolderHelper setBackgroundRes(@IdRes int viewId, int backgroundResId) {
    View view = getView(viewId);
    view.setBackgroundResource(backgroundResId);
    return this;
}

From source file:net.news.inrss.adapter.FiltersCursorAdapter.java

@Override
public void bindView(View view, final Context context, Cursor cursor) {
    TextView isAcceptRuleTextView = (TextView) view.findViewById(android.R.id.text1);
    TextView filterTextTextView = (TextView) view.findViewById(android.R.id.text2);
    TextView isAppliedToTitleTextView = (TextView) view.findViewById(R.id.text3);

    if (cursor.getPosition() == mSelectedFilter) {
        view.setBackgroundResource(
                PrefUtils.getBoolean(PrefUtils.LIGHT_THEME, true) ? R.color.light_accent_color
                        : R.color.dark_accent_color);
    } else {//from  www .j  a  v  a 2  s  .  com
        view.setBackgroundResource(android.R.color.transparent);
    }

    boolean isAcceptRule = cursor.getInt(mIsAcceptRulePosition) == 1;
    isAcceptRuleTextView.setText(isAcceptRule ? R.string.accept : R.string.reject);
    isAcceptRuleTextView.setTextColor(isAcceptRule ? ContextCompat.getColor(context, R.color.green)
            : ContextCompat.getColor(context, R.color.red));
    filterTextTextView.setText(cursor.getString(mFilterTextColumnPosition));
    isAppliedToTitleTextView
            .setText(cursor.getInt(mIsAppliedToTitleColumnPosition) == 1 ? R.string.filter_apply_to_title
                    : R.string.filter_apply_to_content);

    Activity mActivity = (context instanceof Activity) ? (Activity) context : null;
    if (mActivity != null) {
        if (!isZero) {
            mActivity.findViewById(R.id.empty).setVisibility(View.GONE);
        } else {
            mActivity.findViewById(R.id.empty).setVisibility(View.VISIBLE);
        }
    }
}

From source file:com.nxt.njitong.page.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);
            int tabTypefaceStyle = Typeface.NORMAL;
            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 www  .j a va  2 s . c o  m*/
            }
            if (i == selectedPosition) {
                tab.setTextColor(selectedTabTextColor);
            }
        }
    }

}

From source file:de.schildbach.wallet.digitalcoin.ui.ExchangeRatesFragment.java

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    setEmptyText(getString(R.string.exchange_rates_fragment_empty_text));

    adapter = new ResourceCursorAdapter(activity, R.layout.exchange_rate_row, null, true) {
        @Override//www  .  j  a  va2s.com
        public void bindView(final View view, final Context context, final Cursor cursor) {
            final ExchangeRate exchangeRate = ExchangeRatesProvider.getExchangeRate(cursor);
            final boolean isDefaultCurrency = exchangeRate.currencyCode.equals(defaultCurrency);

            view.setBackgroundResource(isDefaultCurrency ? R.color.bg_less_bright : R.color.bg_bright);

            final View defaultView = view.findViewById(R.id.exchange_rate_row_default);
            defaultView.setVisibility(isDefaultCurrency ? View.VISIBLE : View.INVISIBLE);

            final TextView currencyCodeView = (TextView) view
                    .findViewById(R.id.exchange_rate_row_currency_code);
            currencyCodeView.setText(exchangeRate.currencyCode);

            final CurrencyTextView rateView = (CurrencyTextView) view.findViewById(R.id.exchange_rate_row_rate);
            rateView.setPrecision(Constants.LOCAL_PRECISION);
            rateView.setAmount(WalletUtils.localValue(Utils.COIN, exchangeRate.rate));

            final CurrencyTextView walletView = (CurrencyTextView) view
                    .findViewById(R.id.exchange_rate_row_balance);
            walletView.setPrecision(Constants.LOCAL_PRECISION);
            walletView.setAmount(WalletUtils.localValue(balance, exchangeRate.rate));
            walletView.setStrikeThru(Constants.TEST);
            walletView.setTextColor(getResources().getColor(R.color.fg_less_significant));
        }
    };
    setListAdapter(adapter);

    loaderManager.initLoader(0, null, this);
}

From source file:com.blockhead.gussilva.threemorewords.GameActivity.java

public void letterPressed(View view) {

    String ltr = ((TextView) view).getText().toString();
    char letterChar = ltr.charAt(0);
    view.setEnabled(false);/*from  w  ww.j a  v a 2 s.  c  om*/
    view.setBackgroundResource(R.drawable.letter_down);

    //Check if it is a correct guess
    boolean correct = false;

    //Check Word 1
    for (int k = 0; k < currWord1.length(); k++) {
        if (currWord1.charAt(k) == letterChar) {
            correct = true;
            numCorr++;
            answerViews1[k].setTextColor(Color.BLACK);
        }
    }
    //Check Word 2
    for (int k = 0; k < currWord2.length(); k++) {
        if (currWord2.charAt(k) == letterChar) {
            correct = true;
            numCorr++;
            answerViews2[k].setTextColor(Color.BLACK);
        }
    }
    //Check Word 3
    for (int k = 0; k < currWord3.length(); k++) {
        if (currWord3.charAt(k) == letterChar) {
            correct = true;
            numCorr++;
            answerViews3[k].setTextColor(Color.BLACK);
        }
    }

    //Check if user has won, lost, or can continue playing
    if (correct) {
        //correct guess
        if (numCorr == numChars) {
            // Disable Buttons
            disableBtns();

            // Display Alert Dialog
            AlertDialog.Builder winBuild = new AlertDialog.Builder(this);
            winBuild.setTitle("Success");
            winBuild.setMessage(
                    "You win!\n\nThe answers were:\n" + currWord1 + "\n" + currWord2 + "\n" + currWord3);
            winBuild.setPositiveButton("Play Again", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    GameActivity.this.playGame();
                }
            });

            winBuild.setNegativeButton("Exit", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    GameActivity.this.finish();
                }
            });

            winBuild.show();
        }
    } else if (currWrong < numChances) { //User still has chances
        currWrong++;
        view.setBackgroundResource(R.drawable.letter_wrong);
        if ((numChances - currWrong) > 1)
            chancesLeftView.setText((numChances - currWrong) + " chances left");
        else if ((numChances - currWrong) == 1)
            chancesLeftView.setText("1 chance left");
        else
            chancesLeftView.setText("Last Chance!");

        if (currWrong == 3) {
            chancesLeftView.setTextColor(getResources().getColor(R.color.chances_medium));
        } else if (currWrong == 5) {
            chancesLeftView.setTextColor(getResources().getColor(R.color.chances_bad));
        }
    } else { //User has lost
        disableBtns();

        // Display Alert Dialog
        AlertDialog.Builder loseBuild = new AlertDialog.Builder(this);
        loseBuild.setTitle("OOPS");
        loseBuild.setMessage(
                "You lose!\n\nThe answers were:\n" + currWord1 + "\n" + currWord2 + "\n" + currWord3);
        loseBuild.setPositiveButton("Play Again", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                GameActivity.this.playGame();
            }
        });

        loseBuild.setNegativeButton("Exit", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                GameActivity.this.finish();
            }
        });

        loseBuild.show();
    }

}

From source file:com.amaze.filemanager.adapters.ZipAdapter.java

@Override
public RecyclerView.ViewHolder onCreateHeaderViewHolder(ViewGroup viewGroup) {
    View view = mInflater.inflate(R.layout.listheader, viewGroup, false);
    if (zipViewer.mainActivity.theme1 == 1)
        view.setBackgroundResource(R.color.holo_dark_background);
    HeaderViewHolder holder = new HeaderViewHolder(view);
    return holder;
}