Example usage for android.widget TextView setCompoundDrawablesWithIntrinsicBounds

List of usage examples for android.widget TextView setCompoundDrawablesWithIntrinsicBounds

Introduction

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

Prototype

@android.view.RemotableViewMethod
public void setCompoundDrawablesWithIntrinsicBounds(@Nullable Drawable left, @Nullable Drawable top,
        @Nullable Drawable right, @Nullable Drawable bottom) 

Source Link

Document

Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text.

Usage

From source file:piuk.blockchain.android.ui.AbstractWalletActivity.java

public final void toast(final String text, final int imageResId, final int duration,
        final Object... formatArgs) {

    if (text == null)
        return;//w ww .  j  a v  a2  s.  c o  m

    final View view = getLayoutInflater().inflate(R.layout.transient_notification, null);
    TextView tv = (TextView) view.findViewById(R.id.transient_notification_text);
    tv.setText(String.format(text, formatArgs));
    tv.setCompoundDrawablesWithIntrinsicBounds(imageResId, 0, 0, 0);

    final Toast toast = new Toast(this);
    toast.setView(view);
    toast.setDuration(duration);
    toast.show();
}

From source file:feipai.qiangdan.my.SuperAwesomeCardFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    FrameLayout fl = new FrameLayout(getActivity());
    fl.setLayoutParams(params);/*  w w w .j a  va2  s . c om*/

    final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40,
            getResources().getDisplayMetrics());

    TextView v = new TextView(getActivity());
    params.setMargins(margin, margin, margin, margin);
    v.setLayoutParams(params);
    v.setGravity(Gravity.CENTER);
    //      v.setBackgroundResource(R.drawable.ic_launcher);
    //      v.setText("CARD " + (position + 1));
    v.setText(" ");
    v.setTextSize(20);
    v.setTextColor(getActivity().getResources().getColor(R.color.address_title_color));
    //        Drawable drawable = getActivity().getDrawable(R.drawable.icon_no_order);
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_no_order);
    BitmapDrawable bitmapDrawable = new BitmapDrawable(bitmap);
    //TextViewdrawableleft
    v.setCompoundDrawablesWithIntrinsicBounds(null, bitmapDrawable, null, null);

    fl.addView(v);
    return fl;
}

From source file:com.sflib.CustomView.baseview.RoundRecPagerSlidingTabStrip.java

private void addTipIconTextTab(final int position, String title, int resId, boolean tipShow, int iconLocation) {
    View tab = inflate(getContext(), R.layout.tip_text_tab, null);
    TextView titleTV = (TextView) tab.findViewById(R.id.title);
    titleTV.setText(title);/*w  w w. j  av  a  2s .  c  o m*/
    titleTV.setGravity(Gravity.CENTER);
    switch (iconLocation) {
    case IconTabProvider.KIcon_Left:
        titleTV.setCompoundDrawablesWithIntrinsicBounds(resId, 0, 0, 0);
        break;
    case IconTabProvider.KIcon_Right:
        titleTV.setCompoundDrawablesWithIntrinsicBounds(0, 0, resId, 0);
        break;
    case TipIconTabProvider.KIcon_Bottom:
        titleTV.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, resId);
        break;
    case TipIconTabProvider.KIcon_Top:
    default:
        titleTV.setCompoundDrawablesWithIntrinsicBounds(0, resId, 0, 0);
        break;
    }

    tab.findViewById(R.id.tip).setVisibility(tipShow ? View.VISIBLE : View.INVISIBLE);

    addTab(position, tab);
}

From source file:io.github.hidroh.materialistic.ItemActivity.java

@SuppressWarnings("ConstantConditions")
private void bindData(@Nullable final WebItem story) {
    if (story == null) {
        return;// www. j  av a 2s. c  om
    }
    mCustomTabsDelegate.mayLaunchUrl(Uri.parse(story.getUrl()), null, null);
    bindFavorite();
    mSessionManager.view(this, story.getId());
    mVoteButton.setVisibility(View.VISIBLE);
    mVoteButton.setOnClickListener(v -> vote(story));
    final TextView titleTextView = (TextView) findViewById(android.R.id.text2);
    if (story.isStoryType()) {
        titleTextView.setText(story.getDisplayedTitle());
        setTaskTitle(story.getDisplayedTitle());
        if (!TextUtils.isEmpty(story.getSource())) {
            TextView sourceTextView = (TextView) findViewById(R.id.source);
            sourceTextView.setText(story.getSource());
            sourceTextView.setVisibility(View.VISIBLE);
        }
    } else {
        CharSequence title = AppUtils.fromHtml(story.getDisplayedTitle());
        titleTextView.setText(title);
        setTaskTitle(title);
    }

    final TextView postedTextView = (TextView) findViewById(R.id.posted);
    postedTextView.setText(story.getDisplayedTime(this));
    postedTextView.append(story.getDisplayedAuthor(this, true, 0));
    postedTextView.setMovementMethod(LinkMovementMethod.getInstance());
    switch (story.getType()) {
    case Item.JOB_TYPE:
        postedTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_work_white_18dp, 0, 0, 0);
        break;
    case Item.POLL_TYPE:
        postedTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_poll_white_18dp, 0, 0, 0);
        break;
    }
    mAdapter = new ItemPagerAdapter(this, getSupportFragmentManager(),
            new ItemPagerAdapter.Builder().setItem(story).setShowArticle(!mExternalBrowser)
                    .setCacheMode(getIntent().getIntExtra(EXTRA_CACHE_MODE, ItemManager.MODE_DEFAULT))
                    .setDefaultViewMode(mStoryViewMode));
    mAdapter.bind(mViewPager, mTabLayout, mNavButton, mReplyButton);
    mTabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager) {
        @Override
        public void onTabReselected(TabLayout.Tab tab) {
            mAppBar.setExpanded(true, true);
        }
    });
    if (story.isStoryType() && mExternalBrowser) {
        findViewById(R.id.header_card_view)
                .setOnClickListener(v -> AppUtils.openWebUrlExternal(ItemActivity.this, story, story.getUrl(),
                        mCustomTabsDelegate.getSession()));
    } else {
        findViewById(R.id.header_card_view).setClickable(false);
    }
    if (mFullscreen) {
        setFullscreen();
    }
}

From source file:cn.hollo.www.custom_view.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title, int leftIcon) {
    TextView tab = new TextView(getContext());
    tab.setText(title);//from  w w w.  j a  v  a 2s.  c o  m
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    if (tabTextColor != null)
        tab.setTextColor(tabTextColor);
    else
        tab.setTextColor(defaultTabTextColor);

    tab.setCompoundDrawablesWithIntrinsicBounds(leftIcon, 0, 0, 0);
    tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
    addTab(position, tab);
}

From source file:com.hua.weget.PagerSlidingTabStrip.java

private void updateTabStyles() {

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

        View v = tabsContainer.getChildAt(i);

        v.setBackgroundResource(tabBackgroundResId);
        selectedTabTextColor = context.getResources().getColor(R.color.homefragment_top_title_color);
        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabTextColor);
            tab.setCompoundDrawablesWithIntrinsicBounds(context.getResources().getDrawable(mDrawableIds[i]),
                    null, null, null);/*w w  w. j a v a2  s. c om*/

            // 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));
                }
            }
            if (i == selectedPosition) {
                tab.setTextColor(selectedTabTextColor);
                tab.setCompoundDrawablesWithIntrinsicBounds(
                        context.getResources().getDrawable(mDrawableIdsSleect[i]), null, null, null);
            }
        }
    }

}

From source file:com.baseutil.strip.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);
            if (tabResources != null) {
                tab.setCompoundDrawablesWithIntrinsicBounds(tabResources[i], 0, 0, 0);
            }/*from   w  ww.  j  a v  a  2 s  .  com*/
            // 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.astuetz.PagerSlidingTabStripMenu.java

private void addIconTab2(final int position, String title, int resId) {

    TextView tab = new TextView(getContext());
    tab.setText(title);/*w w w  .  j a v a 2  s .c  o  m*/
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    tab.setCompoundDrawablePadding(mTabDrawablePadding);

    switch (mIconPostion) {
    case Left:
        tab.setCompoundDrawablesWithIntrinsicBounds(resId, 0, 0, 0);
        break;
    case Top:
        tab.setCompoundDrawablesWithIntrinsicBounds(0, resId, 0, 0);
        break;
    case Right:
        tab.setCompoundDrawablesWithIntrinsicBounds(0, 0, resId, 0);
        break;
    case Bottom:
        tab.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, resId);
        break;
    }

    addTab(position, tab);
}

From source file:com.heath_bar.tvdb.SeriesOverview.java

protected void ShowHideEpisodes(View seasonRow) {

    // Get the linear layout that we will be adding/removing the episodes to/from
    LinearLayout epLinearLayout = (LinearLayout) seasonRow;

    if (epLinearLayout.getChildCount() == 1) { // if collapsed, expand (add) the seasons

        TextView seasonText = (TextView) seasonRow.findViewById(R.id.season_text);
        seasonText.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.arrow_down),
                null, null, null);//from  w  ww  .j  a  v  a2 s.  c  om

        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        for (int i = 0; i < episodeList.size(); i++) {
            if (seasonRow.getId() == episodeList.get(i).getSeason()) {
                View episodeView = inflater.inflate(R.layout.episode_text_row, epLinearLayout, false);

                episodeView.setBackgroundColor(
                        AppSettings.listBackgroundColors[i % AppSettings.listBackgroundColors.length]);

                TextView text = (TextView) episodeView.findViewById(R.id.text);
                String nameText = String.format("%02d", episodeList.get(i).getNumber()) + " "
                        + episodeList.get(i).getName();
                text.setText(nameText);
                text.setTextSize(textSize);
                text.setId(episodeList.get(i).getId());

                episodeView.setOnClickListener(episodeListener);
                epLinearLayout.addView(episodeView);
            }
        }
    } else { // else season is expanded, collapse it
        TextView seasonText = (TextView) seasonRow.findViewById(R.id.season_text);
        seasonText.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.arrow_right),
                null, null, null);

        for (int i = epLinearLayout.getChildCount() - 1; i > 0; i--) {
            epLinearLayout.removeView(epLinearLayout.getChildAt(i));
        }

    }

}

From source file:com.bwash.bwashcar.view.PagerSlidingTabStrip.java

private void updateTabStyles() {

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

        View v = tabsContainer.getChildAt(i);
        if (pager.getAdapter() instanceof IconTabProvider) {
            TextView tab = (TextView) v.findViewById(R.id.text);
            tab.setTextSize(TypedValue.COMPLEX_UNIT_DIP, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(((IconTabProvider) pager.getAdapter()).getPageTextColor(i));
            tab.setCompoundDrawablesWithIntrinsicBounds(
                    getResources().getDrawable(((IconTabProvider) pager.getAdapter()).getPageIconResId(i)),
                    null, null, null);/*from w  w  w  .  j av  a 2s.co  m*/
            //            tab.setBackgroundDrawable(getResources().getDrawable(((IconTabProvider)pager.getAdapter()).getPageIconResId(i)));
            // 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));
                }
            }
        } else {
            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_DIP, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(0xffffffff);
            // 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));
                }
            }
        }
    }

}