Example usage for android.util TypedValue COMPLEX_UNIT_SP

List of usage examples for android.util TypedValue COMPLEX_UNIT_SP

Introduction

In this page you can find the example usage for android.util TypedValue COMPLEX_UNIT_SP.

Prototype

int COMPLEX_UNIT_SP

To view the source code for android.util TypedValue COMPLEX_UNIT_SP.

Click Source Link

Document

#TYPE_DIMENSION complex unit: Value is a scaled pixel.

Usage

From source file:com.arlib.floatingsearchview.util.Util.java

public static int spToPx(int sp) {
    DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, metrics);
}

From source file:com.koushikdutta.superuser.ActivityIntro.java

@Override
public void onSlideChanged(@Nullable Fragment oldFragment, @Nullable Fragment newFragment) {
    super.onSlideChanged(oldFragment, newFragment);

    if (newFragment != null && newFragment.getView() != null) {
        View parent = newFragment.getView();

        TextView title = (TextView) parent.findViewById(R.id.title);

        if (title != null) {
            if (!(newFragment instanceof FragmentIntro))
                title.setTextColor(0xffeaeaea);
            title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25);

            if (Build.VERSION.SDK_INT > 15)
                title.setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL));
        }//ww w .  jav  a2 s  . c  o m

        TextView desc = (TextView) parent.findViewById(R.id.description);

        if (desc != null) {
            desc.setTextColor(0xffe9e9e9);
            desc.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15.5f);
            desc.setLineSpacing(1f, 1);

            //if (Build.VERSION.SDK_INT > 15) desc.setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL));

        }
    }
}

From source file:com.g_node.gca.abstracts.AbstractCursorAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    // TODO Auto-generated method stub
    /*//  w  w w  .j  a va 2s .  c  om
     * TextView for showing Title
     */
    TextView title = (TextView) view.findViewById(R.id.abTitle);
    title.setText(cursor.getString(cursor.getColumnIndexOrThrow("TITLE")));
    /*
     * TextView for showing Topic
     */
    TextView topic = (TextView) view.findViewById(R.id.abTopic);
    topic.setText(cursor.getString(cursor.getColumnIndexOrThrow("TOPIC")));
    /*
     * TextView for Showing Type
     */
    TextView type = (TextView) view.findViewById(R.id.abType);
    int absSortID = cursor.getInt(cursor.getColumnIndexOrThrow("SORTID"));

    if (absSortID != 0) {
        int groupid = ((absSortID & (0xFFFF << 16)) >> 16);

        switch (groupid) {
        case 0:
            type.setText("Invited Talk");
            type.setBackgroundColor(Color.parseColor("#33B5E5"));
            break;

        case 1:
            type.setText("Contributed Talk");
            type.setBackgroundColor(Color.parseColor("#ef4172"));
            break;

        case 2:
            type.setText("Poster");
            type.setBackgroundColor(Color.parseColor("#AA66CC"));
            break;

        case 3:
            type.setText("Poster");
            type.setBackgroundColor(Color.parseColor("#AA66CC"));
            break;
        default:
            break;
        }

        //absSortID.append("Group ID: " + get_groupid_str(groupid));

    } else {
        //type.setVisibility(View.GONE);
        type.setTextSize(TypedValue.COMPLEX_UNIT_SP, 4);
        type.setVisibility(View.INVISIBLE);
    }

    /*
    Following piece of commented code isn't needed as Abstract Type is 
    selected now based on GroupID. Previously it was being selected based on 'isTalk' field
    but now it's selected on basis of GroupID extracted from SortID. 
            
    String typeText = cursor.getString(cursor.getColumnIndexOrThrow("TYPE"));
    type.setText(typeText.toUpperCase());
            
    if(typeText.compareToIgnoreCase("poster") == 0) {
       type.setBackgroundColor(Color.parseColor("#AA66CC"));
    } else {
       type.setBackgroundColor(Color.parseColor("#33B5E5"));
    }
    */

    /*
     * _id for getting Author Names
     */
    String value = cursor.getString(cursor.getColumnIndexOrThrow("_id"));

    String authorNamesQuery = "SELECT ABSTRACT_UUID, AUTHORS_DETAILS.AUTHOR_UUID, AUTHORS_DETAILS.AUTHOR_FIRST_NAME, AUTHOR_MIDDLE_NAME, AUTHOR_LAST_NAME, AUTHOR_EMAIL, ABSTRACT_AUTHOR_POSITION_AFFILIATION.AUTHOR_POSITION as _aPos FROM ABSTRACT_AUTHOR_POSITION_AFFILIATION LEFT OUTER JOIN AUTHORS_DETAILS USING (AUTHOR_UUID) WHERE ABSTRACT_UUID = '"
            + value + "' ORDER BY _aPos;";
    cursorOne = DatabaseHelper.database.rawQuery(authorNamesQuery, null);

    if (cursorOne != null) {
        cursorOne.moveToFirst();
        /*
         * Name format will be like this A, B & C or A,B,C & D. So, if the
         * name is the last name. We should use '&' before the name
         */
        do {

            if (cursorOne.getPosition() == 0) {
                /*
                 * First data
                 */
                getName = cursorOne.getString(cursorOne.getColumnIndexOrThrow("AUTHOR_FIRST_NAME")) + " "
                        + cursorOne.getString(cursorOne.getColumnIndexOrThrow("AUTHOR_LAST_NAME"));
            } else if (cursorOne.isLast()) {
                /*
                 * Last Data
                 */
                getName = getName + " & "
                        + cursorOne.getString(cursorOne.getColumnIndexOrThrow("AUTHOR_FIRST_NAME")) + " "
                        + cursorOne.getString(cursorOne.getColumnIndexOrThrow("AUTHOR_LAST_NAME"));
            } else {
                getName = getName + " , "
                        + cursorOne.getString(cursorOne.getColumnIndexOrThrow("AUTHOR_FIRST_NAME")) + " "
                        + cursorOne.getString(cursorOne.getColumnIndexOrThrow("AUTHOR_LAST_NAME"));

            }

        } while (cursorOne.moveToNext());
    }

    /*
     * TextView for Author Names
     */
    TextView authorNames = (TextView) view.findViewById(R.id.absAuthorNames);
    /*
     * Get Width
     */
    WindowManager WinMgr = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    @SuppressWarnings("deprecation")
    int displayWidth = WinMgr.getDefaultDisplay().getWidth();
    Paint paint = new Paint();
    Rect bounds = new Rect();
    int text_width = 0;
    paint.getTextBounds(getName, 0, getName.length(), bounds);
    /*
     * Getting Text Width
     */
    text_width = bounds.width();
    /*
     * If Text Width is greater than Display Width Then show First Name et
     * al.
     */
    if (text_width > displayWidth) {
        String output = getName.split(",")[0] + " et al. ";
        authorNames.setText(output);

    } else {
        /*
         * Name Format will be like this If the Name is Yasir Adnan So,It
         * will be Y.Adnan
         */
        authorNames.setText(getName.replaceAll("((?:^|[^A-Z.])[A-Z])[a-z]*\\s(?=[A-Z])", "$1."));
    }
}

From source file:alexander.martinz.libs.materialpreferences.MaterialEditTextPreference.java

@Override
public boolean init(Context context, AttributeSet attrs) {
    if (mInit) {//from w  w w  .  jav  a 2s. co m
        return false;
    }
    mInit = true;

    if (!super.init(context, attrs)) {
        return false;
    }

    if (mEditTextValue == null) {
        mEditTextValue = new EditText(context);
        mEditTextValue.setText(mDefaultValue);
        if (mPrefTextColor != -1) {
            if (isInEditMode()) {
                mEditTextValue.setTextColor(Color.parseColor("#009688"));
            } else {
                mEditTextValue.setTextColor(ContextCompat.getColor(context, mPrefTextColor));
            }
        }
        if (mPrefTextSize != -1) {
            mEditTextValue.setTextSize(TypedValue.COMPLEX_UNIT_SP, mPrefTextSize);
        }
        mEditTextValue.setInputType(InputType.TYPE_NULL);
        mEditTextValue.setEllipsize(TextUtils.TruncateAt.END);
        mEditTextValue.setOnClickListener(this);
        addToWidgetFrame(mEditTextValue);
    }

    setOnClickListener(this);

    return true;
}

From source file:com.acrylicgoat.houstonbicyclemuseum.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);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }/*from  w  ww .  j av  a2  s .  c o m*/

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        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.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  ww  . j  a v a2  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.amitupadhyay.aboutexample.ui.widget.FabOverlapTextView.java

private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FabOverlapTextView);

    float defaultTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, DEFAULT_TEXT_SIZE_SP,
            getResources().getDisplayMetrics());

    setFabOverlapGravity(a.getInt(R.styleable.FabOverlapTextView_fabGravity, Gravity.BOTTOM | Gravity.RIGHT));
    setFabOverlapHeight(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_fabOverlayHeight, 0));
    setFabOverlapWidth(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_fabOverlayWidth, 0));

    if (a.hasValue(R.styleable.FabOverlapTextView_android_textAppearance)) {
        final int textAppearance = a.getResourceId(R.styleable.FabOverlapTextView_android_textAppearance,
                android.R.style.TextAppearance);
        TypedArray atp = getContext().obtainStyledAttributes(textAppearance, R.styleable.FontTextAppearance);
        paint.setColor(atp.getColor(R.styleable.FontTextAppearance_android_textColor, Color.BLACK));
        paint.setTextSize(atp.getDimensionPixelSize(R.styleable.FontTextAppearance_android_textSize,
                (int) defaultTextSize));
        if (atp.hasValue(R.styleable.FontTextAppearance_font)) {
            paint.setTypeface(FontUtil.get(getContext(), atp.getString(R.styleable.FontTextAppearance_font)));
        }/*from  w  w  w .j  ava 2s. com*/
        atp.recycle();
    }

    if (a.hasValue(R.styleable.FabOverlapTextView_font)) {
        setFont(a.getString(R.styleable.FabOverlapTextView_font));
    }

    if (a.hasValue(R.styleable.FabOverlapTextView_android_textColor)) {
        setTextColor(a.getColor(R.styleable.FabOverlapTextView_android_textColor, 0));
    }
    if (a.hasValue(R.styleable.FabOverlapTextView_android_textSize)) {
        setTextSize(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_android_textSize,
                (int) defaultTextSize));
    }

    lineHeightHint = a.getDimensionPixelSize(R.styleable.FabOverlapTextView_lineHeightHint, 0);
    unalignedTopPadding = getPaddingTop();
    unalignedBottomPadding = getPaddingBottom();

    breakStrategy = a.getInt(R.styleable.FabOverlapTextView_android_breakStrategy,
            Layout.BREAK_STRATEGY_BALANCED);

    a.recycle();
}

From source file:com.markupartist.sthlmtraveling.ui.view.TripView.java

public void updateViews() {
    this.setOrientation(VERTICAL);

    float scale = getResources().getDisplayMetrics().density;

    this.setPadding(getResources().getDimensionPixelSize(R.dimen.list_horizontal_padding),
            getResources().getDimensionPixelSize(R.dimen.list_vertical_padding),
            getResources().getDimensionPixelSize(R.dimen.list_horizontal_padding),
            getResources().getDimensionPixelSize(R.dimen.list_vertical_padding));

    LinearLayout timeStartEndLayout = new LinearLayout(getContext());
    TextView timeStartEndText = new TextView(getContext());
    timeStartEndText.setText(DateTimeUtil.routeToTimeDisplay(getContext(), trip));
    timeStartEndText.setTextColor(ContextCompat.getColor(getContext(), R.color.body_text_1));
    timeStartEndText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);

    ViewCompat.setPaddingRelative(timeStartEndText, 0, 0, 0, (int) (2 * scale));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (RtlUtils.isRtl(Locale.getDefault())) {
            timeStartEndText.setTextDirection(View.TEXT_DIRECTION_RTL);
        }//w  w  w . j a  va 2  s.  c  om
    }

    // Check if we have Realtime for start and or end.
    boolean hasRealtime = false;
    Pair<Date, RealTimeState> transitTime = trip.departsAt(true);
    if (transitTime.second != RealTimeState.NOT_SET) {
        hasRealtime = true;
    } else {
        transitTime = trip.arrivesAt(true);
        if (transitTime.second != RealTimeState.NOT_SET) {
            hasRealtime = true;
        }
    }
    //        if (hasRealtime) {
    //            ImageView liveDrawable = new ImageView(getContext());
    //            liveDrawable.setImageResource(R.drawable.ic_live);
    //            ViewCompat.setPaddingRelative(liveDrawable, 0, (int) (2 * scale), (int) (4 * scale), 0);
    //            timeStartEndLayout.addView(liveDrawable);
    //
    //            AlphaAnimation animation1 = new AlphaAnimation(0.4f, 1.0f);
    //            animation1.setDuration(600);
    //            animation1.setRepeatMode(Animation.REVERSE);
    //            animation1.setRepeatCount(Animation.INFINITE);
    //
    //            liveDrawable.startAnimation(animation1);
    //        }

    timeStartEndLayout.addView(timeStartEndText);

    LinearLayout startAndEndPointLayout = new LinearLayout(getContext());
    TextView startAndEndPoint = new TextView(getContext());
    BidiFormatter bidiFormatter = BidiFormatter.getInstance(RtlUtils.isRtl(Locale.getDefault()));
    startAndEndPoint.setText(String.format("%s  %s", bidiFormatter.unicodeWrap(trip.fromStop().getName()),
            bidiFormatter.unicodeWrap(trip.toStop().getName())));

    startAndEndPoint.setTextColor(getResources().getColor(R.color.body_text_1)); // Dark gray
    startAndEndPoint.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (RtlUtils.isRtl(Locale.getDefault())) {
            startAndEndPoint.setTextDirection(View.TEXT_DIRECTION_RTL);
        }
    }
    ViewCompat.setPaddingRelative(startAndEndPoint, 0, (int) (4 * scale), 0, (int) (4 * scale));
    startAndEndPointLayout.addView(startAndEndPoint);

    RelativeLayout timeLayout = new RelativeLayout(getContext());

    LinearLayout routeChanges = new LinearLayout(getContext());
    routeChanges.setGravity(Gravity.CENTER_VERTICAL);

    LinearLayout.LayoutParams changesLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    changesLayoutParams.gravity = Gravity.CENTER_VERTICAL;

    if (trip.hasAlertsOrNotes()) {
        ImageView warning = new ImageView(getContext());
        warning.setImageResource(R.drawable.ic_trip_deviation);
        ViewCompat.setPaddingRelative(warning, 0, (int) (2 * scale), (int) (4 * scale), 0);
        routeChanges.addView(warning);
    }

    int currentTransportCount = 1;
    int transportCount = trip.getLegs().size();
    for (Leg leg : trip.getLegs()) {
        if (!leg.isTransit() && transportCount > 3) {
            if (leg.getDistance() < 150) {
                continue;
            }
        }
        if (currentTransportCount > 1 && transportCount >= currentTransportCount) {
            ImageView separator = new ImageView(getContext());
            separator.setImageResource(R.drawable.transport_separator);
            ViewCompat.setPaddingRelative(separator, 0, 0, (int) (2 * scale), 0);
            separator.setLayoutParams(changesLayoutParams);
            routeChanges.addView(separator);
            if (RtlUtils.isRtl(Locale.getDefault())) {
                ViewCompat.setScaleX(separator, -1f);
            }
        }

        ImageView changeImageView = new ImageView(getContext());
        Drawable transportDrawable = LegUtil.getTransportDrawable(getContext(), leg);
        changeImageView.setImageDrawable(transportDrawable);
        if (RtlUtils.isRtl(Locale.getDefault())) {
            ViewCompat.setScaleX(changeImageView, -1f);
        }
        ViewCompat.setPaddingRelative(changeImageView, 0, 0, 0, 0);
        changeImageView.setLayoutParams(changesLayoutParams);
        routeChanges.addView(changeImageView);

        if (currentTransportCount <= 3) {
            String lineName = leg.getRouteShortName();
            if (!TextUtils.isEmpty(lineName)) {
                TextView lineNumberView = new TextView(getContext());
                lineNumberView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
                RoundedBackgroundSpan roundedBackgroundSpan = new RoundedBackgroundSpan(
                        LegUtil.getColor(getContext(), leg), Color.WHITE,
                        ViewHelper.dipsToPix(getContext().getResources(), 4));
                SpannableStringBuilder sb = new SpannableStringBuilder();
                sb.append(lineName);
                sb.append(' ');
                sb.setSpan(roundedBackgroundSpan, 0, lineName.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                lineNumberView.setText(sb);

                ViewCompat.setPaddingRelative(lineNumberView, (int) (5 * scale), (int) (1 * scale),
                        (int) (2 * scale), 0);
                lineNumberView.setLayoutParams(changesLayoutParams);
                routeChanges.addView(lineNumberView);
            }
        }

        currentTransportCount++;
    }

    TextView durationText = new TextView(getContext());
    durationText.setText(DateTimeUtil.formatDetailedDuration(getResources(), trip.getDuration() * 1000));
    durationText.setTextColor(ContextCompat.getColor(getContext(), R.color.body_text_1));
    durationText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
    durationText.setTypeface(Typeface.DEFAULT_BOLD);

    timeLayout.addView(routeChanges);
    timeLayout.addView(durationText);

    RelativeLayout.LayoutParams durationTextParams = (RelativeLayout.LayoutParams) durationText
            .getLayoutParams();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        durationTextParams.addRule(RelativeLayout.ALIGN_PARENT_END);
    } else {
        durationTextParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    }
    durationText.setLayoutParams(durationTextParams);

    View divider = new View(getContext());
    ViewGroup.LayoutParams dividerParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1);
    divider.setLayoutParams(dividerParams);

    this.addView(timeLayout);

    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) routeChanges.getLayoutParams();
    params.height = LayoutParams.MATCH_PARENT;
    params.addRule(RelativeLayout.CENTER_VERTICAL);
    routeChanges.setLayoutParams(params);

    this.addView(startAndEndPointLayout);
    this.addView(timeStartEndLayout);

    if (mShowDivider) {
        this.addView(divider);
    }
}

From source file:com.jinzht.pro.smarttablayout.SmartTabLayout.java

public SmartTabLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);
    // Make sure that the Tab Strips fills this View
    setFillViewport(true);/*from www  . j av  a  2s.  co m*/

    final DisplayMetrics dm = getResources().getDisplayMetrics();
    final float density = dm.density;

    int tabBackgroundResId = NO_ID;
    boolean textAllCaps = TAB_VIEW_TEXT_ALL_CAPS;
    ColorStateList textColors;
    float textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP, dm);
    int textHorizontalPadding = (int) (TAB_VIEW_PADDING_DIPS * density);
    int textMinWidth = (int) (TAB_VIEW_TEXT_MIN_WIDTH * density);
    boolean distributeEvenly = DEFAULT_DISTRIBUTE_EVENLY;
    int customTabLayoutId = NO_ID;
    int customTabTextViewId = NO_ID;

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.stl_SmartTabLayout, defStyle, 0);
    tabBackgroundResId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_defaultTabBackground,
            tabBackgroundResId);
    textAllCaps = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_defaultTabTextAllCaps, textAllCaps);
    textColors = a.getColorStateList(R.styleable.stl_SmartTabLayout_stl_defaultTabTextColor);
    textSize = a.getDimension(R.styleable.stl_SmartTabLayout_stl_defaultTabTextSize, textSize);
    textHorizontalPadding = a.getDimensionPixelSize(
            R.styleable.stl_SmartTabLayout_stl_defaultTabTextHorizontalPadding, textHorizontalPadding);
    textMinWidth = a.getDimensionPixelSize(R.styleable.stl_SmartTabLayout_stl_defaultTabTextMinWidth,
            textMinWidth);
    customTabLayoutId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextLayoutId,
            customTabLayoutId);
    customTabTextViewId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextViewId,
            customTabTextViewId);
    distributeEvenly = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_distributeEvenly, distributeEvenly);
    a.recycle();

    this.titleOffset = (int) (TITLE_OFFSET_DIPS * density);
    this.tabViewBackgroundResId = tabBackgroundResId;
    this.tabViewTextAllCaps = textAllCaps;
    this.tabViewTextColors = (textColors != null) ? textColors : ColorStateList.valueOf(TAB_VIEW_TEXT_COLOR);
    this.tabViewTextSize = textSize;
    this.tabViewTextHorizontalPadding = textHorizontalPadding;
    this.tabViewTextMinWidth = textMinWidth;
    this.distributeEvenly = distributeEvenly;

    if (customTabLayoutId != NO_ID) {
        setCustomTabView(customTabLayoutId, customTabTextViewId);
    }

    this.tabStrip = new SmartTabStrip(context, attrs);

    if (distributeEvenly && tabStrip.isIndicatorAlwaysInCenter()) {
        throw new UnsupportedOperationException(
                "'distributeEvenly' and 'indicatorAlwaysInCenter' both use does not support");
    }

    addView(tabStrip, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

}

From source file:com.axum.darivb.searchview.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(bariol_regular_tf);

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

    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;
}