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

The following are Jave code examples for showing how to use setCompoundDrawablesWithIntrinsicBounds() 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: Android-skin-support   File: LastFragment.java   View Source Code Vote up 6 votes
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment, null);
    mEdit = (EditText) view.findViewById(R.id.edit);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        mEdit.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.drawable_left_selector,
                R.drawable.drawable_top_selector,
                R.drawable.drawable_right_selector,
                R.drawable.drawable_bottom_selector);
    }
    mEdit1 = (EditText) view.findViewById(R.id.edit1);
    mEdit1.setCompoundDrawablesWithIntrinsicBounds(R.drawable.drawable_left_selector,
            R.drawable.drawable_top_selector,
            R.drawable.drawable_right_selector,
            R.drawable.drawable_bottom_selector);
    mText1 = (TextView) view.findViewById(R.id.text1);
    mText1.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.drawable_left_selector),
            getResources().getDrawable(R.drawable.drawable_top_selector),
            getResources().getDrawable(R.drawable.drawable_right_selector),
            getResources().getDrawable(R.drawable.drawable_bottom_selector));
    return view;
}
 
Example 2
Project: Review-   File: MainActivity.java   View Source Code Vote up 6 votes
/** 返回设置好的底部按钮
     * @param indicator1
     * @return
     */
    private View getIndicatorView(Indicator indicator1) {
        View view = LayoutInflater.from(this).inflate(R.layout.tab_indicator, null);
        TextView indicator = (TextView) view.findViewById(R.id.tab_title);

        indicator.setText(getString(indicator1.getResName()));

        indicator.setTextSize(TypedValue.COMPLEX_UNIT_SP,10);
        Drawable icon = this.getResources().getDrawable(indicator1.getResIcon());
//        自定义ICON大小
//        icon.setBounds(0, 0, 75, 75);
//        indicator.setCompoundDrawables(null,icon,null,null);
        indicator.setCompoundDrawablePadding(3);
        indicator.setCompoundDrawablesWithIntrinsicBounds(null, icon, null, null);
        indicator.setPadding(0,8,0,5);


        return view;
    }
 
Example 3
Project: prevent   File: UserGuideActivity.java   View Source Code Vote up 6 votes
private boolean setView(int id, String packageName) {
    TextView donate = (TextView) findViewById(id);
    PackageManager pm = getPackageManager();
    try {
        ApplicationInfo info = pm.getApplicationInfo(packageName, 0);
        if (!info.enabled) {
            return false;
        }
        CharSequence label = getLabel(pm, info);
        donate.setContentDescription(label);
        donate.setCompoundDrawablesWithIntrinsicBounds(null, cropDrawable(pm.getApplicationIcon(info)), null, null);
        donate.setText(label);
        donate.setClickable(true);
        donate.setOnClickListener(this);
        donate.setVisibility(View.VISIBLE);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        UILog.d("cannot find package " + packageName, e);
        return false;
    }
}
 
Example 4
Project: buildAPKsSamples   File: GestureBuilderActivity.java   View Source Code Vote up 6 votes
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.gestures_item, parent, false);
    }

    final NamedGesture gesture = getItem(position);
    final TextView label = (TextView) convertView;

    label.setTag(gesture);
    label.setText(gesture.name);
    label.setCompoundDrawablesWithIntrinsicBounds(mThumbnails.get(gesture.gesture.getID()),
            null, null, null);

    return convertView;
}
 
Example 5
Project: MyFire   File: ExpandableTextView.java   View Source Code Vote up 6 votes
/**
 * 初始化viwe
 */
private void findViews() {
    LayoutInflater inflater = (LayoutInflater) getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.item_expand_shink, this);
    mTvContent = (TextView) findViewById(R.id.expandable_text);
    mTvContent.setOnClickListener(this);
    mTvExpandCollapse = (TextView) findViewById(R.id.expand_collapse);
    if(showExpandCollapseDrawable) {
        mTvExpandCollapse.setCompoundDrawablesWithIntrinsicBounds(null, null, mCollapsed ? mExpandDrawable : mCollapseDrawable, null);
    }
    mTvExpandCollapse.setText(mCollapsed ? getResources().getString(R.string.expand) : getResources().getString(R.string.shink));
    mTvExpandCollapse.setOnClickListener(this);

    mTvContent.setTextColor(contentTextColor);
    mTvContent.getPaint().setTextSize(contentTextSize);

    mTvExpandCollapse.setTextColor(collapseExpandTextColor);
    mTvExpandCollapse.getPaint().setTextSize(collapseExpandTextSize);

    //设置收起展开位置:左或者右
    LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
    lp.gravity = grarity;
    mTvExpandCollapse.setLayoutParams(lp);
}
 
Example 6
Project: TMP-Music_player   File: MainActivity.java   View Source Code Vote up 6 votes
private void setupTabIcons() {

        TextView tabOne = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
        tabOne.setText("ONE");
        tabOne.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.play, 0, 0);
        tabLayout.getTabAt(0).setCustomView(tabOne);

        TextView tabTwo = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
        tabTwo.setText("TWO");
        tabTwo.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.music_list, 0, 0);
        tabLayout.getTabAt(1).setCustomView(tabTwo);

        TextView tabThree = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
        tabThree.setText("THREE");
        tabThree.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.youtube, 0, 0);
        tabLayout.getTabAt(2).setCustomView(tabThree);
    }
 
Example 7
Project: aos-Video   File: BrowserCategory.java   View Source Code Vote up 6 votes
public View getView(int position, View convertView, ViewGroup parent) {
    final int type = getItemViewType(position);
    if (convertView == null) {
        if (type == ITEM_VIEW_TYPE_CATEGORY) {
            convertView = inflater.inflate(R.layout.browser_category_item_shortcut, parent, false);
        } else {
            convertView = inflater.inflate(R.layout.browser_category_item_separator, parent, false);
        }
    }

    final TextView tv = (TextView) convertView;
    if (type == ITEM_VIEW_TYPE_CATEGORY) {
        convertView.setBackgroundResource(R.drawable.category_item_background_normal);
        // Set the category name
        ItemData item = (ItemData) mCategoryList.get(position);
        tv.setText(item.text);
        if(item.icon!=-1)
            tv.setCompoundDrawablesWithIntrinsicBounds(item.icon, 0 , 0 , 0);
        else tv.setCompoundDrawablesWithIntrinsicBounds(0, 0 , 0 , 0);
    }
    else {
        tv.setText((CharSequence) mCategoryList.get(position));
    }

    return convertView;
}
 
Example 8
Project: FakeWeather   File: CardWeatherAdapter.java   View Source Code Vote up 6 votes
@Override
protected void convert(final BaseViewHolder helper, WeatherCity item) {
    TextView tvName = helper.getView(R.id.tv_card_city_name);
    if (helper.getAdapterPosition() == 0) {
        tvName.setCompoundDrawablesWithIntrinsicBounds(null, null,
                ThemeUtil.setTintDrawable(R.drawable.ic_location, mContext,
                        ThemeUtil.getCurrentColorPrimary(mContext)), null);
    }
    tvName.setText(item.getCityName());
    helper.setText(R.id.tv_card_weather, TextUtils.isEmpty(item.getWeatherText()) ? "NA" : item.getWeatherText());
    helper.setText(R.id.tv_card_temp, TextUtils.isEmpty(item.getWeatherTemp()) ? "NA" : item.getWeatherTemp() + "℃");
    final ImageView imageView = helper.getView(R.id.iv_card_weather);
    WeatherUtil.getInstance().getWeatherDict(item.getWeatherCode()).observeOn(AndroidSchedulers.mainThread()).subscribe(new SimpleSubscriber<WeatherBean>() {
        @Override
        public void onNext(WeatherBean weatherBean) {
            Glide.with(mContext).load(weatherBean.getIcon()).diskCacheStrategy(DiskCacheStrategy.ALL).into(imageView);
        }
    });
}
 
Example 9
Project: android-social-fragment   File: SocialFragment.java   View Source Code Vote up 5 votes
private void applyIconTint(Bundle args, TextView textView, @DrawableRes int drawableRes) {
    if (args.getInt(ARG_ICON_TINT) != 0) {
        Drawable drawable = getResources().getDrawable(drawableRes);
        Drawable wrappedDrawable = DrawableCompat.wrap(drawable);
        DrawableCompat.setTint(wrappedDrawable, ContextCompat.getColor(getActivity(), args.getInt(ARG_ICON_TINT)));
        textView.setCompoundDrawablesWithIntrinsicBounds(wrappedDrawable, null, null, null);
    }
}
 
Example 10
Project: Idea-ChainSelector   File: ChainSelectorView.java   View Source Code Vote up 5 votes
private void removeItems(int tag) {

        for (int i = tabList.size() - 1; i > tag; i--) {
            tabList.remove(i);
            tabParent.removeViewAt(i);
        }
        TextView textView = (TextView) tabParent.getChildAt(tag);
        textView.setTextColor(selectorColor);
        textView.setCompoundDrawablesWithIntrinsicBounds(null,null,null,null);
        compileScroll();
        resetListViewSelector();
    }
 
Example 11
Project: NeiHanDuanZiTV   File: MediaItemLayout.java   View Source Code Vote up 5 votes
public void setMedia(BaseMedia media) {
    if (media instanceof ImageMedia) {
        mVideoLayout.setVisibility(GONE);
        setCover(((ImageMedia) media).getThumbnailPath());
    } else if (media instanceof VideoMedia) {
        mVideoLayout.setVisibility(VISIBLE);
        VideoMedia videoMedia = (VideoMedia) media;
        TextView durationTxt = ((TextView) mVideoLayout.findViewById(R.id.video_duration_txt));
        durationTxt.setText(videoMedia.getDuration());
        durationTxt.setCompoundDrawablesWithIntrinsicBounds(BoxingManager.getInstance().getBoxingConfig().getVideoDurationRes(), 0, 0, 0);
        ((TextView) mVideoLayout.findViewById(R.id.video_size_txt)).setText(videoMedia.getSizeByUnit());
        setCover(videoMedia.getPath());
    }
}
 
Example 12
Project: MySelfDemo   File: SuperTextView_mySelef.java   View Source Code Vote up 5 votes
/**
 * 设置 textview 的 drawableLeft  drawableRight  drawablePadding
 *
 * @param textView
 * @param drawableLeft
 * @param drawableRight
 * @param drawablePadding
 */
public void setDefaultDrawable(TextView textView, Drawable drawableLeft, Drawable drawableRight, int drawablePadding) {
    if (drawableLeft != null || drawableRight != null) {
        textView.setVisibility(VISIBLE);
    }

    textView.setCompoundDrawablesWithIntrinsicBounds(drawableLeft, null, drawableRight, null);
    textView.setCompoundDrawablePadding(drawablePadding);
}
 
Example 13
Project: RecyclerViewPreferences   File: IconStyleWithIcon.java   View Source Code Vote up 5 votes
@Override
public View updateLayout(boolean topLayout, int position, View view, boolean dropdown, boolean selected) {
    // the defuault layout is an TextView
    TextView tv = (TextView) view;
    tv.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.ic_launcher, 0, 0, 0);
    return view;
}
 
Example 14
Project: zabbkit-android   File: MenuAdapter.java   View Source Code Vote up 5 votes
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = ((Activity) context).getLayoutInflater();
    View row = convertView;
    if(row == null) {
        row = inflater.inflate(resource, parent, false);
    }

    TextView txtTitle = (TextView) row.findViewById(R.id.drawer_item_text);

    if (items != null && items.length > position) {
        txtTitle.setText(items[position]);
        switch (position) {
            case 0:
                txtTitle.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_drawer_overview, 0, 0, 0);
                break;
            case 1:
                txtTitle.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_drawer_bookmarks, 0, 0, 0);
                break;
            case 2:
                txtTitle.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_drawer_notifications, 0, 0, 0);
                break;
            case 3:
                txtTitle.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_server, 0, 0, 0);
                break;
            case 4:
                txtTitle.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_drawer_about, 0, 0, 0);
                break;
            case 5:
                txtTitle.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_drawer_logout, 0, 0, 0);
                break;
        }
    }

    return row;
}
 
Example 15
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 16
Project: Customerly-Android-SDK   File: IE_Attachment.java   View Source Code Vote up 5 votes
void addAttachmentToInput(@NonNull IAct_AInput pA_Customerly_Activity) {
    pA_Customerly_Activity._Attachments.add(this);
    TextView tv = new TextView(pA_Customerly_Activity);
    tv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
    tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.io_customerly__ld_chat_attachment, 0, 0, 0);
    int _5dp = IU_Utils.px(5);
    tv.setCompoundDrawablePadding(_5dp);
    tv.setPadding(_5dp, 0, 0, 0);
    tv.setTextColor(IU_Utils.getColorStateListFromResource(pA_Customerly_Activity.getResources(), R.color.io_customerly__textcolor_malibu_grey));
    tv.setLines(1);
    tv.setSingleLine();
    tv.setEllipsize(TextUtils.TruncateAt.MIDDLE);
    tv.setTypeface(Typeface.SANS_SERIF, Typeface.NORMAL);
    tv.setText(this.name);
    tv.setOnClickListener(textView -> new AlertDialog.Builder(pA_Customerly_Activity)
            .setTitle(R.string.io_customerly__choose_a_file_to_attach)
            .setMessage(pA_Customerly_Activity.getString(R.string.io_customerly__cancel_attachment, tv.getText()))
            .setNegativeButton(R.string.io_customerly__cancel, null)
            .setPositiveButton(R.string.io_customerly__remove, (dlg, which) -> {
                ViewGroup vg = (ViewGroup)tv.getParent();
                if(vg != null) {
                    vg.removeView(tv);
                }
                pA_Customerly_Activity._Attachments.remove(this);
            })
            .setCancelable(true)
            .show());
    pA_Customerly_Activity.input_attachments.addView(tv);
}
 
Example 17
Project: chromium-for-android-56-debug-video   File: BillingAddressAdapter.java   View Source Code Vote up 5 votes
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
    View view;

    // Add a "+" icon and a blue tint to the last element.
    if (position == getCount() - 1) {
        view = super.getDropDownView(position, convertView, parent);
        TextView tv = (TextView) view;
        Resources resources = getContext().getResources();

        // Create the "+" icon, put it left of the text and add appropriate padding.
        tv.setCompoundDrawablesWithIntrinsicBounds(
                TintedDrawable.constructTintedDrawable(
                    resources, R.drawable.plus, R.color.light_active_color),
                null, null, null);
        tv.setCompoundDrawablePadding(
                resources.getDimensionPixelSize(R.dimen.payments_section_large_spacing));

        // Set the correct appearance, face and style for the text.
        ApiCompatibilityUtils.setTextAppearance(tv, R.style.PaymentsUiSectionAddButtonLabel);
        tv.setTypeface(Typeface.create(
                resources.getString(R.string.roboto_medium_typeface),
                R.integer.roboto_medium_textstyle));
    } else {
        // Don't use the recycled convertView, as it may have the style of the last element.
        view = super.getDropDownView(position, null, parent);
    }

    return view;
}
 
Example 18
Project: androidthings-kuman-sm9   File: BindingAdapters.java   View Source Code Vote up 4 votes
@BindingAdapter("connectionStatus")
public static void setVisibility(TextView textView, @ConnectionStatus @DrawableRes int connectionStatus) {
    textView.setCompoundDrawablesWithIntrinsicBounds(connectionStatus, 0, 0, 0);
}
 
Example 19
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 20
Project: letv   File: TextViewCompat.java   View Source Code Vote up 4 votes
public void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView, @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, @Nullable Drawable bottom) {
    textView.setCompoundDrawablesWithIntrinsicBounds(start, top, end, bottom);
}