Java Code Examples for android.widget.TextView.setCompoundDrawablesRelativeWithIntrinsicBounds()

The following are Jave code examples for showing how to use setCompoundDrawablesRelativeWithIntrinsicBounds() of the android.widget.TextView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: chromium-net-for-android   File: ApiCompatibilityUtils.java   View Source Code Vote up 5 votes
/**
 * @see android.widget.TextView#setCompoundDrawablesRelativeWithIntrinsicBounds(Drawable,
 *      Drawable, Drawable, Drawable)
 */
public static void setCompoundDrawablesRelativeWithIntrinsicBounds(TextView textView,
        Drawable start, Drawable top, Drawable end, Drawable bottom) {
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) {
        // Work around the platform bug described in setCompoundDrawablesRelative() above.
        boolean isRtl = isLayoutRtl(textView);
        textView.setCompoundDrawablesWithIntrinsicBounds(isRtl ? end : start, top,
                isRtl ? start : end, bottom);
    } else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) {
        textView.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom);
    } else {
        textView.setCompoundDrawablesWithIntrinsicBounds(start, top, end, bottom);
    }
}
 
Example 2
Project: chromium-net-for-android   File: ApiCompatibilityUtils.java   View Source Code Vote up 5 votes
/**
 * @see android.widget.TextView#setCompoundDrawablesRelativeWithIntrinsicBounds(int, int, int,
 *      int)
 */
public static void setCompoundDrawablesRelativeWithIntrinsicBounds(TextView textView,
        int start, int top, int end, int bottom) {
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) {
        // Work around the platform bug described in setCompoundDrawablesRelative() above.
        boolean isRtl = isLayoutRtl(textView);
        textView.setCompoundDrawablesWithIntrinsicBounds(isRtl ? end : start, top,
                isRtl ? start : end, bottom);
    } else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) {
        textView.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom);
    } else {
        textView.setCompoundDrawablesWithIntrinsicBounds(start, top, end, bottom);
    }
}
 
Example 3
Project: AggregationNews   File: MainActivity.java   View Source Code Vote up 5 votes
private void initTab() {
    TextView firstView = (TextView) LayoutInflater.from(this).inflate(R.layout.bottom_tab_item, null);
    firstView.setText(mTabResources[0][0]);
    firstView.setTextColor(ContextCompat.getColor(MainActivity.this, R.color.colorPrimary));
    firstView.setCompoundDrawablesRelativeWithIntrinsicBounds(0, Integer.valueOf(mTabResources[0][1]), 0, 0);
    firstView.getCompoundDrawables()[1].setColorFilter(ContextCompat.getColor(MainActivity.this, R.color.colorPrimary), PorterDuff.Mode.SRC_IN);
    mTabLayout.getTabAt(0).setCustomView(firstView);

    for (int i = 1; i < 3; i++) {
        TextView textView = (TextView) LayoutInflater.from(this).inflate(R.layout.bottom_tab_item, null);
        textView.setText(mTabResources[i][0]);
        textView.setCompoundDrawablesRelativeWithIntrinsicBounds(0, Integer.valueOf(mTabResources[i][1]), 0, 0);
        mTabLayout.getTabAt(i).setCustomView(textView);
    }

}
 
Example 4
Project: SudoCAM-Ku   File: ArrayAdapterWithIcon.java   View Source Code Vote up 5 votes
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = super.getView(position, convertView, parent);
    TextView textView = (TextView) view.findViewById(android.R.id.text1);
    textView.setTextSize(18);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        textView.setCompoundDrawablesRelativeWithIntrinsicBounds(images.get(position), 0, 0, 0);
    } else {
        textView.setCompoundDrawablesWithIntrinsicBounds(images.get(position), 0, 0, 0);
    }
    textView.setCompoundDrawablePadding(
            (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getContext().getResources().getDisplayMetrics()));
    return view;
}
 
Example 5
Project: android-AutofillFramework   File: NavigationItem.java   View Source Code Vote up 5 votes
public NavigationItem(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr,
        int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationItem,
            defStyleAttr, defStyleRes);
    String labelText = typedArray.getString(R.styleable.NavigationItem_labelText);
    String infoText = typedArray.getString(R.styleable.NavigationItem_infoText);
    Drawable logoDrawable = typedArray.getDrawable(R.styleable.NavigationItem_itemLogo);
    @ColorRes int colorRes = typedArray.getResourceId(R.styleable.NavigationItem_imageColor, 0);
    String launchingActivityName = typedArray.getString(R.styleable.NavigationItem_destinationActivityName);
    int imageColor = ContextCompat.getColor(getContext(), colorRes);
    typedArray.recycle();
    View rootView = LayoutInflater.from(context).inflate(R.layout.navigation_item, this);
    TextView buttonLabel = rootView.findViewById(R.id.buttonLabel);
    buttonLabel.setText(labelText);
    if (logoDrawable != null) {
        Drawable mutatedLogoDrawable = logoDrawable.mutate();
        mutatedLogoDrawable.setColorFilter(imageColor, PorterDuff.Mode.SRC_IN);
        buttonLabel.setCompoundDrawablesRelativeWithIntrinsicBounds(mutatedLogoDrawable, null,
                null, null);
    }
    InfoButton infoButton = rootView.findViewById(R.id.infoButton);
    infoButton.setInfoText(infoText);
    infoButton.setColorFilter(imageColor);
    CardView outerView = rootView.findViewById(R.id.cardView);
    outerView.setOnClickListener((view) -> {
        if (launchingActivityName != null) {
            Intent intent = new Intent();
            intent.setClassName(getContext().getPackageName(), launchingActivityName);
            context.startActivity(intent);
        } else {
            Log.w(TAG, "Launching Activity name not set.");
        }
    });
}
 
Example 6
Project: RLibrary   File: UIItem.java   View Source Code Vote up 5 votes
private static TextView makeItem(Context context, ItemInfo info) {
    TextView textView = new TextView(context);
    textView.setCompoundDrawablesRelativeWithIntrinsicBounds(info.leftIcoResId == -1 ? null :
                    context.getResources().getDrawable(info.leftIcoResId), null,
            info.rightIcoResId == -1 ? null : context.getResources().getDrawable(info.rightIcoResId), null);
    textView.setText(info.itemText);
    textView.setTextColor(info.textColor);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, info.textSize);
    textView.setGravity(Gravity.CENTER_VERTICAL);
    textView.setCompoundDrawablePadding((int) dpToPx(context, 8));
    textView.setPadding(0, 0, (int) dpToPx(context, 8), 0);
    textView.setOnClickListener(info.clickListener);
    textView.setBackgroundResource(info.backgroundResId);
    return textView;
}
 
Example 7
Project: XinFramework   File: CommonTitleBar.java   View Source Code Vote up 4 votes
/**
 * 初始化主视图左边部分
 *
 * @param context
 */
private void initMainLeftViews(Context context) {
    LayoutParams leftInnerParams = new LayoutParams(WRAP_CONTENT, MATCH_PARENT);
    leftInnerParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    leftInnerParams.addRule(RelativeLayout.CENTER_VERTICAL);

    if (leftType == TYPE_LEFT_TEXTVIEW) {
        // 初始化左边TextView
        tvLeft = new TextView(context);
        tvLeft.setId(ViewFinder.generateViewId());
        tvLeft.setText(leftText);
        tvLeft.setTextColor(leftTextColor);
        tvLeft.setTextSize(TypedValue.COMPLEX_UNIT_PX, leftTextSize);
        tvLeft.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
        tvLeft.setSingleLine(true);
        tvLeft.setOnClickListener(this);
        // 设置DrawableLeft及DrawablePadding
        if (leftDrawable != 0) {
            tvLeft.setCompoundDrawablePadding((int) leftDrawablePadding);
            if (SysUtils.hasJellyBeanMr1()) {
                tvLeft.setCompoundDrawablesRelativeWithIntrinsicBounds(leftDrawable, 0, 0, 0);
            } else {
                tvLeft.setCompoundDrawablesWithIntrinsicBounds(leftDrawable, 0, 0, 0);
            }
            tvLeft.setPadding(0, 0, PADDING_5, 0);
        } else {
            tvLeft.setPadding(PADDING_5, 0, PADDING_5, 0);
        }

        rlMain.addView(tvLeft, leftInnerParams);
        mFadeViewList.add(tvLeft);
    } else if (leftType == TYPE_LEFT_IMAGEBUTTON) {
        // 初始化左边ImageButton
        btnLeft = new ImageButton(context);
        btnLeft.setId(ViewFinder.generateViewId());
        btnLeft.setBackgroundColor(Color.TRANSPARENT);
        btnLeft.setImageResource(leftImageResource);
        btnLeft.setPadding(PADDING_12, 0, PADDING_12, 0);
        btnLeft.setOnClickListener(this);

        rlMain.addView(btnLeft, leftInnerParams);
        mFadeViewList.add(btnLeft);
    } else if (leftType == TYPE_LEFT_CUSTOM_VIEW) {
        // 初始化自定义View
        viewCustomLeft = LayoutInflater.from(context).inflate(leftCustomViewRes, null);
        if (viewCustomLeft.getId() == 0) {
            viewCustomLeft.setId(ViewFinder.generateViewId());
        }
        rlMain.addView(viewCustomLeft, leftInnerParams);
        mFadeViewList.add(viewCustomLeft);
    }
}
 
Example 8
Project: boohee_v5.6   File: TextViewCompatJbMr2.java   View Source Code Vote up 4 votes
public static void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView, @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, @Nullable Drawable bottom) {
    textView.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom);
}
 
Example 9
Project: boohee_v5.6   File: TextViewCompatJbMr2.java   View Source Code Vote up 4 votes
public static void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView, @DrawableRes int start, @DrawableRes int top, @DrawableRes int end, @DrawableRes int bottom) {
    textView.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom);
}
 
Example 10
Project: buildAPKsSamples   File: ContactViewBinder.java   View Source Code Vote up 2 votes
/**
 * Binds the {@code textView} with the specified {@code contact}.
 *
 * @param contact  The contact.
 * @param textView The TextView.
 */
public static void bind(Contact contact, TextView textView) {
    textView.setText(contact.getName());
    textView.setCompoundDrawablesRelativeWithIntrinsicBounds(contact.getIcon(), 0, 0, 0);
}