Example usage for android.widget TextView setPadding

List of usage examples for android.widget TextView setPadding

Introduction

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

Prototype

@Override
public void setPadding(int left, int top, int right, int bottom) 

Source Link

Usage

From source file:com.aero2.android.DefaultActivities.SmogMapActivity.java

public void showNoInternetScreen() {
    showLoadingScreen();/* ww  w .j  a  va 2  s .co  m*/
    ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
    progressBar.setVisibility(View.INVISIBLE);
    TextView noConnectionTV = (TextView) findViewById(R.id.loading_tv);
    noConnectionTV.setText("NO INTERNET CAN'T DOWNLOAD DATA FOR THE FIRST TIME :(");
    noConnectionTV.setTextColor(Color.GRAY);
    noConnectionTV.setPadding(40, 30, 40, 0);
}

From source file:com.honeywell.printer.indicator.TabPageIndicator.java

/**
 * ?/*from   w  w  w.ja  v  a  2s .  c  om*/
 *
 * @param index tab
 * @param count ?
 */
public void showTabMsgCountView(int index, int count, int res) {
    if (mTabLayout != null) {
        final TextView msgCountView = (TextView) mTabLayout.findViewById(index + ID_OFFSET);
        if (msgCountView != null) {
            final int color = getResources().getColor(R.color.new_msg_num_text_color);
            msgCountView.setTextColor(color);
            msgCountView.setGravity(Gravity.CENTER);
            msgCountView.setTypeface(Typeface.DEFAULT_BOLD);
            // final int paddingPixels = Tools.dp2px(2);
            int paddingPixels = (int) getResources().getDimension(R.dimen.indicator_num_padding);
            msgCountView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
            final LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            final int badgeMarginLeft = (int) getResources().getDimension(R.dimen.indicator_marginleft);
            final int badgeMarginBottom = (int) getResources().getDimension(R.dimen.indicator_marginbottom);
            params.gravity = Gravity.CENTER;
            params.setMargins(badgeMarginLeft, 0, 0, badgeMarginBottom);
            if (count == 0) {
                msgCountView.setVisibility(View.GONE);
                return;
            } else if (count > 99) {
                msgCountView.setText("99+");
                msgCountView.setBackgroundResource(R.drawable.tab_msg_num_big_bg);
            } else {
                msgCountView.setText(String.valueOf(count));
                msgCountView.setBackgroundResource(res);
            }
            msgCountView.setTextSize(11);
            msgCountView.setLayoutParams(params);
            msgCountView.setVisibility(View.VISIBLE);
        }

    }
}

From source file:com.bruno.distribuciones.android.SlidingTabLayout.java

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);//w w  w.  ja v  a  2 s  .c  o m

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);
    return textView;
}

From source file:com.coolerfall.uiart.PagerSlidingTabStrip.java

/** add one number indicator tab */
private void addNumTab(final int position, String title, int num) {
    LinearLayout tab = new LinearLayout(getContext());
    TextView titleText = new TextView(getContext());
    TextView numText = new TextView(getContext());

    titleText.setText(title);//from   ww  w  .j  av a 2 s  . c o  m
    titleText.setGravity(Gravity.CENTER);
    titleText.setSingleLine();

    numText.setText(Integer.toString(num));
    numText.setGravity(Gravity.CENTER);
    numText.setPadding(mNumPadding, 1, mNumPadding, 1);
    numText.setSingleLine();

    /* if the number is 0, set invisible */
    if (num == 0) {
        numText.setVisibility(View.GONE);
    } else {
        numText.setVisibility(View.VISIBLE);
    }

    tab.addView(titleText, 0, mDefaultTabLayoutParams);
    tab.addView(numText, 1, mNumLayoutParams);
    tab.setGravity(Gravity.CENTER);

    addTab(position, tab);
}

From source file:com.yktx.check.widget.OldPagerSlidingTabStrip.java

private void addIconAndTextTab(final int position, int resId, String title) {
    LinearLayout layout = new LinearLayout(getContext());
    layout.setGravity(Gravity.CENTER);//  w ww.j  ava 2 s  . c  om
    layout.setOrientation(LinearLayout.VERTICAL);
    ImageView tabImage = new ImageView(getContext());
    tabImage.setImageResource(resId);
    tabImage.setId(R.id.image);
    TextView tabText = new TextView(getContext());
    tabText.setText(title);
    tabText.setSingleLine();
    tabText.setId(R.id.text);
    tabText.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    tabText.setGravity(Gravity.CENTER_HORIZONTAL);
    tabText.setPadding(0, 3, 0, 0);
    layout.addView(tabImage);
    layout.addView(tabText);

    addTab(position, layout);

}

From source file:com.example.wechatsample.utils.widget.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {

    TextView tab = new TextView(getContext());
    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    //      final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm);
    //      params.setMargins(0, 255, 0, 255);
    tab.setLayoutParams(params);//from   w  ww.ja va  2  s. c  o m
    tab.setLayoutParams(params);
    tab.setPadding(tabPadding, 0, tabPadding, 0);
    tab.setText(title);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    addTab(position, tab);
}

From source file:com.example.nigel.hackathon.helpers.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  . 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);

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);
    return textView;
}

From source file:com.mydatingapp.ui.base.SkBaseInnerActivity.java

public void setActionBarLogoCounter(int count) {
    ImageView logo = (ImageView) findViewById(android.R.id.home);

    if (count < 1) {
        currentLogoCounter = 0;//from  w w  w.  j  a  v a 2 s. com
        logo.setVisibility(View.GONE);
        return;
    } else {
        logo.setVisibility(View.VISIBLE);
    }

    currentLogoCounter = count;

    TextView v = new TextView(getApp());
    v.setText(new Integer(count).toString());
    v.setBackgroundResource(R.drawable.sidebar_menu_counterbg);
    v.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
    v.setDrawingCacheEnabled(true);
    v.setTextColor(Color.WHITE);
    v.setPadding(SKDimensions.convertDpToPixel(6, getApp()), 0, SKDimensions.convertDpToPixel(6, getApp()), 0);

    ActionBar.LayoutParams paramsExample = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
            ActionBar.LayoutParams.WRAP_CONTENT, 1);
    paramsExample.setMargins(0, 0, 0, 0);
    v.setHeight(SKDimensions.convertDpToPixel(20, getApp()));
    v.setLayoutParams(paramsExample);

    // this is the important code :)
    // Without it the view will have a dimension of 0,0 and the bitmap will be null
    v.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());

    v.buildDrawingCache(true);
    Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
    v.setDrawingCacheEnabled(false);

    logo.setImageDrawable(new BitmapDrawable(getApp().getResources(), b));
    logo.setPadding(SKDimensions.convertDpToPixel(3, getApp()), 0, 0, 0);
}

From source file:org.openremote.android.console.AppSettingsActivity.java

/**
 * Creates the image cache text view.//  ww  w. ja v  a 2  s  .co  m
 * 
 * @return the text view
 */
private TextView createCacheText() {
    TextView cacheText = new TextView(this);
    cacheText.setPadding(10, 5, 0, 5);
    cacheText.setText("Image Cache:");
    cacheText.setBackgroundColor(Color.DKGRAY);
    return cacheText;
}

From source file:com.chaos.dmactiontabsexample.view.SlidingTabLayout.java

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);/*from   w  ww .j  a v  a 2  s . c om*/

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}