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:de.mdxdave.materialbreadcrumbsnavigation.MaterialBreadcrumbsNavigation.java

private void addItem(final NavigationItem item, int position, boolean isRoot, boolean setActive) {
    LayoutInflater vi = (LayoutInflater) context.getApplicationContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = vi.inflate(R.layout.item_view, null);

    int last;/*from   w ww  . j a  v a 2  s .  c o m*/
    if (isRoot) {
        last = 0;
        list.add(item);
    } else if (position == -1) {
        last = viewGroup.getChildCount();
        last = (last < 0) ? 0 : last;
        list.add(item);
    } else {
        last = position;
        list.set(position, item);
    }

    final TextView textView = (TextView) v.findViewById(R.id.breadcrumbnav_textView);
    textView.setTextColor(darkenColor(textColor));
    textView.setText(item.getTitle().toUpperCase());

    item.setId(last);

    final int finalLast = last;
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            setActive(finalLast, false, true);
        }
    });

    ImageView imageView = (ImageView) v.findViewById(R.id.breadcrumbnav_imageView);
    imageView.setColorFilter(indicatorColor, PorterDuff.Mode.MULTIPLY);

    // Padding and root item
    if (isRoot) {
        imageView.setVisibility(View.GONE);
        int padding_left = 48;
        int padding_right = 12;
        int padding = 18;
        final float scale = getResources().getDisplayMetrics().density;
        int padding_left_px = (int) (padding_left * scale + 0.5f);
        int padding_right_px = (int) (padding_right * scale + 0.5f);
        int padding_px = (int) (padding * scale + 0.5f);
        textView.setPadding(padding_left_px, padding_px, padding_right_px, padding_px);
    }

    // Scroll to end

    final int finalLast1 = last;
    horizontalScrollView.post(new Runnable() {
        @Override
        public void run() {
            if (finalLast1 == viewGroup.getChildCount())
                horizontalScrollView.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
        }
    });

    viewGroup.addView(v, last, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    if (setActive || getCurrent() == position || list.size() == 0)
        setActive(last, true);
}

From source file:apps.junkuvo.alertapptowalksafely.MainActivity.java

private Toast createToastShort(String text) {
    Toast toast = new Toast(this);
    TextView tv = new TextView(this);
    tv.setText(text);//  w  w  w . j av  a2s.  co  m
    tv.setTextColor(ContextCompat.getColor(this, R.color.colorAccent));
    tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, TOAST_TEXT_SIZE);
    //        int pixel = (int)mWindowDensity * 56;
    int toastMargin = getResources().getDimensionPixelSize(R.dimen.toast_margin_top_bottom);
    tv.setPadding(0, toastMargin, 0, toastMargin);
    toast.setView(tv);
    toast.setGravity(mToastPosition, 0, 0);
    toast.setDuration(Toast.LENGTH_SHORT);

    return toast;
}

From source file:com.do_an_httt.truon_000.jobssocialnetwork.view.SlidingTabLayoutEmployeeUpdate.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  ww .jav  a  2 s  .c  o  m
 */
protected TextView createDefaultTabView(Context context) {
    int width_device = getResources().getDisplayMetrics().widthPixels;
    TextView textView = new TextView(context);
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(width_device / 2,
            ViewGroup.LayoutParams.MATCH_PARENT);
    textView.setLayoutParams(params);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

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

    return textView;
}

From source file:com.fierydevs.mytablayout.materialtabs.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)}./*from   ww w. j a va2  s.  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));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

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

    return textView;
}

From source file:com.ylsg365.pai.activity.view.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)}.//from  ww w  .j  ava  2 s  .  c o  m
 */
@SuppressLint("NewApi")
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.setWidth(caculateScreenX() / tabCount);
    textView.setTextColor(tabTextColorNormal);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        //            getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
        //                    outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

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

    return textView;
}

From source file:com.ch.ch_library.smartlayout.SmartTabLayout.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)}./*from www . j  a va2  s .  c  o m*/
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextColor(mTabViewTextColor);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTabViewTextSize);
    textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(mTabViewTextAllCaps);
    }

    textView.setPadding(mTabViewTextHorizontalPadding, 0, mTabViewTextHorizontalPadding, 0);

    if (mTabViewTextMinWidth > 0) {
        textView.setMinWidth(mTabViewTextMinWidth);
    }

    return textView;
}

From source file:com.example.larry.miplayer.view.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)}./*from   w  ww.ja va  2 s.c  o  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);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

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

    /*********** BEGIN OF MY CODE*/
    /* Set color to white */
    textView.setTextColor(Color.WHITE);
    /*********** END OF MY CODE*/

    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

From source file:com.prateek.eskores.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)}./*from   ww w. j a va  2  s . 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);

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT);
    params.weight = 0.5f;
    textView.setLayoutParams(params);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

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

    return textView;
}

From source file:com.truman.showtime.showtime.ui.view.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)}.//  ww w .  j  av  a2  s.  c om
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setTextColor(Color.WHITE);
    textView.setGravity(Gravity.CENTER);
    textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

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

    return textView;
}

From source file:com.bryan.example.widget.slidingtablayout.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)}.
 *//*from  w w  w  .  j  a  v a  2 s . c om*/
@SuppressLint("NewApi")
protected TextView createDefaultTabView(Context context) {
    /**
     * ?Holo??
     */
    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.setTypeface(Typeface.DEFAULT);

    // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
    // {
    // // If we're running on Honeycomb or newer, then we can use the
    // // Theme's
    // // selectableItemBackground to ensure that the View has a pressed
    // // state
    // TypedValue outValue = new TypedValue();
    // getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
    // outValue, true);
    // textView.setBackgroundResource(outValue.resourceId);
    // }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the
        // Action Bar tab style
        textView.setAllCaps(true);
    }

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

    return textView;
}